I just upgraded to PHP7 and got this warning :
Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in line 322
How do I replace preg_replace (the second preg_replace in below code) to preg_replace_callback? It's a 3rd party code which I don't really understand. I know some PHP and have tried to look for the solution, but I have trouble understanding it.
// Remove HTML Entities //
$string = preg_replace('/&(#?x?[0-9a-z]+)?;/', '', $string);
$search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
"'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
"'([\r\n])[\s]+'", // Strip out white space
"'&(quot|#34);'i", // Replace HTML entities
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(\d+);'e");
if ($search && $string){
return preg_replace($search, ' ', $string); // Line 322, the line that I need to fix
} else {
return false;
}
eflag doesn't do anything in that case, just remove it.DOMDocumentorstrip_tags. Why removing indentation except for the first line?). Try to understand the goal of this piece of code and rewrite it entirely in a better way.