正则表达式在php中被用来处理复杂的文字串。支持正则表达式的函数有:
ereg()
ereg replace()
eregi replace()
split()
这些函数都将正则表达式作为他们的第一个参数。php使用posix扩展规则表达式(使用posix 1003.2)。要找到所有的关于posix扩展规则表达式的描述,请查看包括在php发行版本之内的regex man页面。
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("^","<br>",$string);
/* put a <br> tag at the beginning of $string. */
ereg_replace("$","<br>",$string);
/* put a <br> tag at the end of $string. */
ereg_replace("\n","",$string);
/* get rid of any carriage return
characters in $string. */
