php remove line containing string code example
Example 1: php remove line if it contains string
$rows = file("problem.txt");
$blacklist = "foo|bar|lol";
foreach($rows as $key => $row) {
if(preg_match("/($blacklist)/", $row)) {
unset($rows[$key]);
}
}
file_put_contents("solved.txt", implode("\n", $rows));
Example 2: string remove line breaks php
preg_replace( "/\r|\n/", "", $yourString );