Home > Backend Development > PHP Tutorial > 正规表达式函数_PHP

正规表达式函数_PHP

WBOY
Release: 2016-06-01 12:39:47
Original
820 people have browsed it

PHP与其它跨平台语言(也许Java不在其列. :))类似,也有正规表达式功能. PHP3.0的正规表达式功能当然远远比不上Perl,但还是足够用的,主要函数有这么些:

(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(正规表达式,字符串,[取出前多少项]);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template