Mega Code Archive

 
Categories / Php / Strings
 

Use regular expression to check each line of the code

<?php   $file = fopen("data.txt", "r") or die("Cannot open file!\n");   while ($line = fgets($file, 1024)) {     if (preg_match("/Hello( World!)?/", $line)) {       echo "Found match:  " . $line;     } else {       echo "No match: " . $line;     }   }   fclose($file); ?>