I’m trying to display a single error message “Match not found”, if the match isn’t found in the while loop. At the moment, I know that if I put an “else” statement inside, it’ll just display “Match not found” for every line until it reaches the end of the loop.
Here’s what I have so far:
<?php
$filename = "roster.txt";
$fp = fopen($filename, "r") or die("Couldn't open $filename");
while(!feof($fp))
{ $line = fgets($fp);
if (preg_match('/Navi/',$line)) {
print "$line<br>";
}
}
fclose($fp)
?>
Thanks for any help I may get!
Set a
matchasfalsebefore while loop and set it totruewhen match is found.After while loop check
matchvariable .