if( $fh = fopen("file.txt", "r") ){
$left='';
while (!feof($fh)) {// read the file
$temp = fread($fh);
$fgetslines = explode("\n",$temp);
$fgetslines[0]=$left.$fgetslines[0];
if(!feof($fh) )$left = array_pop($lines);
foreach($fgetslines as $k => $line){
//This is where you can build your check for the strings you want to remove
//if statement or switch, which ever makes sence with your current logic.
//After excluding your strings from the temp file
//overwrite your original file with the temp file of proper strings that you want.
}
}
}
fclose($fh);
Я думаю, это то, что вы ищете.