Regular expressions are used in PHP to process complex text strings. Functions that support regular expressions include ereg () eregreplace () eregireplace () split (). These functions use regular expressions as their first parameters. PHP uses the POSIX extension rule expression (using POSIX1003.2 ). To find all the descriptions of POSIX extension rule expressions, use a regular expression.
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 ("\ n", "", $ string );
/* Get rid of any carriage return
Characters in $ string .*/