Regular expressions are used in PHP to process complex text strings. Functions that support regular expressions include:
Ereg ()
Ereg replace ()
Eregi replace ()
Split ()
These functions use regular expressions as their first parameter. PHP uses POSIX Extension Rule expressions (using POSIX 1003.2 ). For all the descriptions about POSIX Extension Rule expressions, see the regex man page included in the PHP release.
Example 2-4. Regular expression examples
Ereg ("abc", $ string );
/* Returns true if "abc"
Is found anywhere in $ string .*/
Ereg ("^ abc", $ string );
/* Returns true if "abc"
Is found at the beginning of $ string .*/
Ereg ("abc $", $ string );
/* Returns true if "abc"
Is found at the end of $ string .*/
Eregi ("(ozilla. [23] | MSIE.3)", $ HTTP_USER_AGENT );
/* Returns true if client browser
Is Netscape 2, 3 or MSIE 3 .*/
Ereg ("([[: alnum:] +) ([[: alnum:] +) ([[: alnum:] + )",
$ String, $ regs );
/* Places three space separated words
Into $ regs [1], $ regs [2] and $ regs [3]. */
Ereg_replace ("^ ","
", $ String );
/* Put
Tag at the beginning of $ string .*/
Ereg_replace ("$ ","
", $ String );
/* Put
Tag at the end of $ string .*/
Ereg_replace ("", "", $ string );
/* Get rid of any carriage return
Characters in $ string .*/