The recent server PHP version has been upgraded to 5.6 and found a lot of warnings.
Preg_replace (): the/e modifier is deprecated, use preg_replace_callback instead
At first did not pay attention, and later found a lot of such warnings, so the online search for the php5.5 version of the above to discard the preg_replace function of the/e this modifier means that the modifier is to let the regular replacement of the rule support PHP code
So what should we do?
In fact, as long as the preg_replace inside has the/E modifier code modified to Preg_replace _callback and then re-write it.
Example
For example
Preg_replace ("/([A-z])/E", "' _ '. Strtolower (' \\1 ') ", $STR)
Modified into
Preg_replace_callback ('/([A-z])/', function ($matches) { return ' _ '. Strtolower ($matches [0]); }, $STR)
Can
here is a special warning after the modified/([A-z])/E last e Be sure to get rid of it or make a mistake.
Let's look at a slightly more complicated example.
$patterns = '/'. $begin. $parseTag. $n 1. ' \ (\s*?) '. $end. ' /eis '; $replacement = "\ $this->parsexmltag (' $tagLib ', ' $tag ', ' $ ', ')"; $content = Preg_replace ($ Patterns, $replacement, $content);
This substitution uses a custom method inside the class. If you use the anonymous function to set the message directly, you will be prompted with an error because there is no such method and the variable in the anonymous function context, so use () should be used to introduce and note that you must remove the regular e
$that = $this; $patterns = '/'. $begin. $parseTag. $n 1. ' \ (\s*?) '. $end. ' /is '; $content =preg_replace_callback ($patterns, function ($matches) use ($tagLib, $tag, $that) { return $that Parsexmltag ($tagLib, $tag, $matches [1], ');}, $content);
Use $thit instead of $this here; All right, let's record it here today.
Small smoke original, reproduced please indicate the source!
New version of PHP deprecated preg_replace/e modifier