topical media & game development

talk show tell print

basic-regex-23-preg-grep.php / php



  <html>
  <head>
  <title>A preg_grep() Test</title>
  </head>
  <body>
  <?php
  myArray = array("Hello", "Help", "helper", "shell", "satchel", "Camera");
  myMatchesSensitive = preg_grep("/Hel/", myArray);
  echo "<p>Matching case sensitively:</p>";
  if (myMatchesSensitive)
  {
    print_r (array_values(myMatchesSensitive));
  }
  myMatchesInsensitive = preg_grep("/Hel/i", myArray);
  echo "<br /><p>Matching case insensitively:</p>";
  if (myMatchesInsensitive)
  {
    print_r (array_values(myMatchesInsensitive));
  }
  ?>
  </body>
  </html>


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.