正则表达式格式_PHP教程
程序员文章站
2024-01-27 09:56:04
...
正则表达式在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("^","
",$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. */
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("^","
",$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. */
推荐阅读
-
正则表达式格式_PHP教程
-
php调用MsSQL存储过程使用内置RETVAL获取过程中的return值_PHP教程
-
PHP-----PHP程序设计基础教程----第三章函数
-
PHP-----PHP程序设计基础教程----第二章PHP基本语法
-
php 用户名正则表达式(中文,英文,数字,字母)
-
PHP表单递交控件名称含有点号(.)会被转化为下划线(_)的处理方法_PHP教程
-
php mysql_connect 与mysql_pconnect函数与实例教程
-
php中file_exists函数使用详解_PHP教程
-
PHP之正则表达式捕获组与非捕获组(详解),php正则表达式_PHP教程
-
Apache Reference Manual (10)_PHP教程