New users seek advice ~ Why do I feel useless about the regular expression pattern modifier e? For example, the two pieces of code match the URL link in the string. This uses the pattern modifier e: $ urlPattern & nbsp; (www. | https? : | Ftp: | news: | telnet :) {1} ([^ [] + ?) (Com | net | org) ([w -.? New users seek advice ~ Why do I feel useless about the regular expression pattern modifier e?
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?
Regular PHP
Share:
------ 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.