$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);
this will just look over every line and if it not what you want to delete, it gets pushed to an array that will get written back to the file.