Regular expressions are used in PHP to handle complex strings of text. The functions that support regular expressions are:
Ereg ()
Ereg replace ()
Eregi replace ()
Split ()
Each of these functions takes a regular expression as their first argument. PHP uses POSIX extension rule expressions (using POSIX 1003.2). To find all descriptions of 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 A
Tag at the beginning of $string. */
Ereg_replace ("$", "
", $string);
/* Put A
Tag at the end of $string. */
Ereg_replace ("", "", $string);
/* Get rid of any carriage return
Characters in $string. */
http://www.bkjia.com/PHPjc/531925.html www.bkjia.com true http://www.bkjia.com/PHPjc/531925.html techarticle regular expressions are used in PHP to handle complex strings of text. The functions that support regular expressions are: Ereg () ereg replace () eregi replace () split () These functions all use regular expressions as ...