PHP Use Regular Expression To Check Each Line Of Code – String Function

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

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.