选择显示字体大小

如何使用php中的正则表达式


php中正则表达式用于复杂字符串的处理。所支持的正则表达式如下:
ereg()
ereg_replace()
eregi()
eregi_replace()
split()

(1)ereg,eregi
这是正规表达式匹配函数,前者是大小写有关匹配,后者则是无关的.
用法:
ereg(正规表达式,字符串,[匹配部分数组名]);
php3.0中的正规表达式大体类似于grep中用的.
(2)ereg_replace,eregi_replace
这些是替换函数.
用法:
ereg_replace(正规表达式,替换串,原字符串);
字符串处理函数中有一个strtr,是"翻译"函数,类似于perl中的tr/.../.../,
用法:
strtr(字符串,"从","到");
例如:
strtr("aaabb","ab","cd")返回"cccdd".
(3)split
与explode函数有些类似,但这次可以在匹配某正规表达式的地方分割字符串.
用法:
split(正规表达式,字符串,[取出前多少项]);

这些函数都使用正则字符串做为第一个参数。php使用posix 1003.2标准所定义的扩展正则字符串。
要查考posix正则表达式的完整描述请看php软件包中regex目录下的man页。

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. */

  


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons