January 26th 2007 02:45 pm

An easier way to do simple matches with PHP

Tired of trying to figure out that perfect Perl-style regular expression when all you need to do is a simple match? Well, toss away that ereg or preg_match call you’ve been working on for the last 20 minutes and use your new friend fnmatch(). fnmatch will let you match using POSIX shell command style patterns, which may be much much easier for a non regex guru to wrap their head around.

<?php
if (fnmatch("*gr[ae]y", $color)) {
  echo "some form of gray ...";
}
?>

This function is only available on POSIX compliant systems, so all you Windows PHP users are out of luck.

Enjoy!

2 Comments »

2 Responses to “An easier way to do simple matches with PHP”

  1. Xanax overdose. on 26 Aug 2008 at 3:32 pm #

    Xanax.

    Xanax presciption.

  2. Xanax. on 27 Aug 2008 at 3:02 pm #

    What is xanax.

    Side effects of drug xanax. Hysbysfwrdd cymrux xanax cheap phentermine. Xanax.

Trackback URI | Comments RSS

Leave a Reply

You must be logged in to post a comment.

« Marco Tabini: 5 PHP Performance Tips You Probably Don’t Want To Hear | Easily Syncing Remote Files in Komodo With Unison »