php remove line if it contains string

Solutions on MaxInterview for php remove line if it contains string by the best coders in the world

showing results for - "php remove line if it contains string"
Nathanael
03 Oct 2019
1$rows = file("problem.txt");    
2$blacklist = "foo|bar|lol";
3
4foreach($rows as $key => $row) {
5    if(preg_match("/($blacklist)/", $row)) {
6        unset($rows[$key]);
7    }
8}
9
10file_put_contents("solved.txt", implode("\n", $rows));