0

PHP Code to Implement Fast Pattern Matching

pattern matching in php
Pattern matching is to check for the presence of some string in a given text. You must be wondering what I am intending to convey by the term fast in the title of this article.

Actually, PHP is already well enriched with many string manipulation functions including preg_match at apex , all contributing good for pattern matching. But they all seem to be very slow and with low performance when need to scale big, the pattern matching.

Implement Fast Pattern Matching Using PHP

Like if one needs to search for multiple words or patterns simultaneously in a text, existing PHP functions fail to provide desired performance.

PHP has added a wonderful package under its stock with name

“PHP fast pattern matching”

The full code can be downloaded from here:

http://www.phpclasses.org/browse/package/8994/download/zip.html

The main file inside this package is fastpm.php which contains the definition of the main class facilitating the fast pattern matching php.

fastpm.php

and here is the example using this wonderful class.

Example.php

Here is the Output:

computer, pattern, match, of, of, of, of, pattern, pattern, match, pattern, of

The Output Reveals Some Interesting Points Here:

  • Output displays all the search patterns if present, with each pattern displayed exactly the number of times, it is present in the given text.
  • The output exactly follows the order in which the pattern is present in the given text.

Now have a try with this package for Fast Pattern Matching in PHP and tell me isn’t it fast?

Hopefully you would like this. Thanks

Manish Kumar

Leave a Reply

Your email address will not be published. Required fields are marked *