下一篇 » « 上一篇

正则表达式格式

作者:爱好者    时间:2008-01-22    来源:php之家    点击:781    本文共1篇文章 字体:[ ]

正则表达式格式

正则表达式在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
php学习之家http://www.444p.com


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. */

责任编辑:semirock
发表评论
密码: (游客不需要密码)
记住我【Alt+S 或 Ctrl+Enter 快速提交】

搜索工具


《PHP精通》点击排行