How can you iterate through multiple lines in a file in PHP to output specific lines based on a search string?

To iterate through multiple lines in a file in PHP and output specific lines based on a search string, you can use the `fgets()` function to read each line in the file and then use `strpos()` to check if the search string exists in that line. If the search string is found, you can output that line.

$searchString = "example";
$filename = "file.txt";

$file = fopen($filename, "r");
if ($file) {
    while (($line = fgets($file)) !== false) {
        if (strpos($line, $searchString) !== false) {
            echo $line;
        }
    }
    fclose($file);
} else {
    echo "Error opening the file.";
}