正则表达式格式

王朝other·作者佚名  2008-05-21
窄屏简体版  字體: |||超大  

正则表达式在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 browseris Netscape 2, 3 or MSIE 3. */ereg("([[:alnum:]]+) ([[:alnum:]]+) ([[:alnum:]]+ )",$string,$regs);/* Places three space separated wordsinto $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 returncharacters in $string. */

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航