Php Remove Line If It Contains String

[Solved] Php Remove Line If It Contains String | Php - Code Explorer | yomemimo.com
Question : php remove line if it contains string

Answered by : geeky-bravo

$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));

Source : https://stackoverflow.com/a/2267793/212889 | Last Update : Thu, 03 Sep 20

Answers related to php remove line if it contains string

Code Explorer Popular Question For Php