The new php version discards the preg_replacee modifier. recently, the php version of the server was upgraded to 5.6, and many warnings were reported.
preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead
I didn't pay attention to it at the beginning. later I found many such warnings, so I checked it on the internet and found that php5.5 and above abandoned the modifier/e in the preg_replace function, which means that the replacement rule supports php code during regular expression replacement.
So what should we do?
In fact, you only need to change the code with the/e modifier in preg_replace to preg_replace _ callback and write it again.
Example
For example
preg_replace("/([A-Z])/e", "'_' . strtolower('\\1')", $str)
Modify
preg_replace_callback('/([A-Z])/', function ($matches) { return '_' . strtolower($matches[0]); }, $str)
You can.
Here special warning after modification/([A-Z])/e LastEBe sure to remove it. Otherwise, an error will occur.
Next, let's look at an example of a slightly complex point.
$patterns = '/'.$begin.$parseTag.$n1.'\/(\s*?)'.$end.'/eis';$replacement = "\$this->parseXmlTag('$tagLib','$tag','$1','')";$content = preg_replace($patterns, $replacement,$content);
This replacement uses the custom method in the class. if you use an anonymous function to directly set the method, an error will be prompted because the anonymous function context does not have this method and the variable, so use () in addition, you must remove e from the regular expression.
$that = $this;$patterns = '/'.$begin.$parseTag.$n1.'\/(\s*?)'.$end.'/is';$content=preg_replace_callback($patterns, function($matches) use($tagLib,$tag,$that){ return $that->parseXmlTag($tagLib,$tag,$matches[1],'');},$content);
Use $ thit to replace $ this. now, record it here today.