Home  >  Article  >  Backend Development  >  Regular Expression Function_PHP Tutorial

Regular Expression Function_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 10:59:50766browse

​ PHP is similar to other cross-platform languages ​​(maybe Java is not one of them. :)), and it also has regular expression functions. Of course, the regular expression function of PHP3.0 is far inferior to Perl, but it is still useful enough. The main functions are as follows Some:
(1) ereg, eregi
This is a regular expression matching function. The former is case-related matching, while the latter is irrelevant.
Usage: ereg(regular expression, string, [match part of array name]);
The regular expressions in PHP3.0 are roughly similar to those used in grep.

(2)ereg_replace,eregi_replace
These are replacement functions.
Usage:
ereg_replace(regular expression, replacement string, original string);
There is a strtr in the string processing function, which is a "translation" function, similar to tr/.../.../,
in Perl Usage: strtr(string,"from","to");
For example: strtr("aaabb","ab","cd") returns "cccdd".

(3)split
It is similar to the explode function, but this time you can split the string where it matches a regular expression.
Usage:
split(regular expression, string, [remove the first number of items]);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445572.htmlTechArticlePHP is similar to other cross-platform languages ​​(maybe Java is not one of them. :)) and also has regular expression functions. Of course, the regular expression function of PHP3.0 is far inferior to that of Perl, but it is still useful enough. The main functions are...
Statement:
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