电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> PHP>>PHP 3 专题 -- 正则表达式格式:

PHP 3 专题 -- 正则表达式格式

来源:www.cncfan.com | 2006-1-11 | (有1962人读过)


正则表达式在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. */
PHP热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号