Home > Article > Backend Development > Regular Expression Function_PHP Tutorial
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]);