| [ Team LiB ] |
|
22.2 Regular ExpressionsFortunately, PHP offers something more powerful than the strtok function: regular expressions. Written in a language of their own, regular expressions describe patterns that are compared to strings. The PHP source code includes an implementation of regular expressions that conforms to the POSIX 1003.2 standard. This standard allows for expressions of an older style but encourages a modern style that I will describe. All the regular expression functions are described in Chapter 12. In 1999 Andrei Zmievski added support for regular expressions that follow the style of Perl. They offer two advantages over PHP native regular expressions. They make it easier to copy an expression from a Perl script, and they take less time to execute. It is beyond the scope of this text to examine regular expressions in depth. It is a subject worthy of a book itself. I will explain the basics as well as demonstrate the various PHP functions that use regular expressions. An excellent resource for learning more about regular expressions is Chapter 2 of Ellie Quigley's UNIX Shells by Example. If you are interested in PERL-style regular expressions, check the official PERL documentation site first <http://www.perldoc.com/perl5.8.0/pod/perlre.html>. You will then need to read the documentation at the PHP site itself that lists the differences between Perl and the PHP implementation <http://www.php.net/manual/pcre.pattern.syntax.php>. There are several differences in the PHP implementation, but most PERL expressions execute unmodified in PHP. |
| [ Team LiB ] |
|