>백엔드 개발 >PHP 튜토리얼 >正则表达式格式_PHP

正则表达式格式_PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB원래의
2016-06-01 12:32:46994검색

正则表达式

正则表达式在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("\n","",$string);

/* Get rid of any carriage return

characters in $string. */

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.