shachi
08-20-2006, 02:22 PM
Can anyone tell me how do I delete a certain word from a file?? I was using this script found on http://php.net/file
$key = "test";
$fc=file("some.txt");
$f=fopen("some.txt","w");
foreach($fc as $line){
if (!strstr($line,$key))
fputs($f,$line);
}
fclose($f);
}
the problem with this code is it deletes all the lines related to the key. For e.g if the key is test it deletes test1 test2 test3 and every word that has the key.
I need a script that deletes only the exact key supplied.
Hope that makes sense.Any help would be appreciated. Thanks.
$key = "test";
$fc=file("some.txt");
$f=fopen("some.txt","w");
foreach($fc as $line){
if (!strstr($line,$key))
fputs($f,$line);
}
fclose($f);
}
the problem with this code is it deletes all the lines related to the key. For e.g if the key is test it deletes test1 test2 test3 and every word that has the key.
I need a script that deletes only the exact key supplied.
Hope that makes sense.Any help would be appreciated. Thanks.