$DELETE = "the_line_you_want_to_delete"; $data = file("./foo.txt"); $out = array(); foreach($data as $line) { if(trim($line) != $DELETE) { $out[] = $line; } } $fp = fopen("./foo.txt", "w+"); flock($fp, LOCK_EX); foreach($out as $line) { fwrite($fp, $line); } flock($fp, LOCK_UN); fclose($fp);
it will just look at each line, and if this is not what you want to delete, it gets into an array that will be written back to the file.
Thusitha Sumanadasa
source share