Hi,
I'm trying to fully automate my website, and I'm trying to delete a line from a file that matches the line in a given String.
For example, I have a txt file named toApprove.txt containing a list of names such as:
John
Joe
George
Jake
The file is kept in that format. So, if I have a variable holding "Joe", how do I remove the line that says "Joe" from the text file and keep the rest. here's what I tried ($_GET["file"] represents the line I want to remove):
$file=fopen("toApprove.txt","r+");
$file2=fopen("temp.txt","w+");
while(!feof($file))
{
$str = fgets($file);
if($str != $_GET["file"])
{
fwrite($file2,$str);
}
}
fclose($file);
fclose($file2);
$file=fopen("toApprove.txt","w+");
$file2=fopen("temp.txt","r");
while(!feof($file2))
{
$str = fgets($file2);
fwrite($file,$str);
}
fclose($file);
fclose($file2);
Thanks so much for your help!