How PHP uses preg_replace ()
This article mainly shows you "how PHP uses preg_replace ()". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "how PHP uses preg_replace ()".
Preg_replace ()
Function prototype: mixed preg_replace (mixed $pattern, mixed $replacement, mixed $subject [, int $limit])
Preg_replace is more powerful than ereg_replace. Arrays can be used for the first three parameters; the fourth parameter, $limit, sets the number of replacements, which defaults to all substitutions. Code 6.7 is an application example of array substitution.
Code 6.7 Array replacement
The code is as follows:
The output is as follows.
Name: Thomas Ching ", Email: tom@emailaddress.com Address: No.5, Wilson St., New York, U.S.A
The pattern modifier "e" can be used in preg_replace 's regular expressions. Its purpose is to use the matching result as an expression and can be recalculated. For example:
The code is as follows: