当前位置:首页 > 网络编程 > WEB编程 > PHP > 正则表达式格式

正则表达式格式

点击次数:25 次 发布日期:2008-11-26 02:46:28 作者:源代码网
源代码网推荐
源代码网推荐

源代码网整理以下  正则表达式在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(" ","",$string);
/* Get rid of any carriage return
characters in $string. */


源代码网推荐
源代码网推荐
源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华