New users seek advice ~ Why do I feel useless about the regular expression pattern modifier e? Regular PHP
For example, the two codes match the URL link in the string.
Here is the pattern modifier e:
$ UrlPattern = "/(www. | https? : \/| Ftp: \/| news: \/| telnet :\/\/) {1} ([^ \ [\ "'] + ?) (Com | net | org) (\/[\ w -\.\/\? \ % \ & \ =] *)? /Ei ";
$ Url = "PHP address: www.php.com ";
Echo preg_replace ($ urlPattern, "'\ 2'.' \ 3'", $ url );
Here is the pattern modifier e:
$ UrlPattern = "/(www. | https? : \/| Ftp: \/| news: \/| telnet :\/\/) {1} ([^ \ [\ "'] + ?) (Com | net | org) (\/[\ w -\.\/\? \ % \ & \ =] *)? /I ";
$ Url = "PHP address: www.php.com ";
Echo preg_replace ($ urlPattern, '\ 2'.' \ 3', $ url );
The output results are the same ~
All of them are replacing www.php.com with php.com.
I think that's just a matter of double quotation marks ,,,
Instead, it's easier to use e.
What is e?
Reply to discussion (solution)
E (PREG_REPLACE_EVAL)
If this modifier is set, preg_replace () will evaluate and execute the replaced string as php code (eval function mode) after the replacement string is replaced by a reference ), and use the execution result as the string to be replaced. Single quotation marks, double quotation marks, backslash (\), and NULL characters are escaped by backslash when being replaced by backward references.