Reputation: 35
I was wondering if someone might be able to help me with this one.
We are receiving this error in our error logs:
[13-Mar-2018 16:42:40 UTC] PHP Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in public_html/check_requirements.php on line 58
Line 58 of check_requirements.php is:
$string = preg_replace('~�*([0-9]+);~e', 'chr(\\1)', $string);
I'm afraid we just host the web site for someone else and the error appears to have occurred due to a recent PHP upgrade.
Does anyone know how I can alter line 58 of the code to fix the problem?
Many thanks for your help
James
15/03/2018
Thanks Eydamos. I've replaced the line in the code with your suggestion
$string = preg_replace_callback(
'~�*([0-9]+);~',
function ($matches) {
return chr($matches[1]);
},
$string
);
Unfortunately I then loaded the site again and checked the error log and it came up with the following:
[15-Mar-2018 09:02:09 UTC] PHP Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in public_html/check_requirements.php on line 57
Line 57 was:
$string = preg_replace('~�*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
It looks like your first suggestions fixed that issue but then another one has become apparent. I'm not sure what I should do with this one either. Would you mind taking a look for me? If it helps, I can paste the entire code.
I really appreciate your help with this one. It's totally out of my area of expertise - just something that we've inherited from an old site we've taken over the hosting of.
Upvotes: 0
Views: 7237
Reputation: 601
This is an easy fix you just have to convert the second parameter into a function. Like this:
$string = preg_replace_callback(
'~�*([0-9]+);~',
function ($matches) {
return chr($matches[1]);
},
$string
);
Beside you can archive the same result way easier:
$string = html_entity_decode($string);
The second one is just as easy as the first one:
$string = preg_replace_callback(
'~�*([0-9a-f]+);~i',
function ($matches) {
return chr(hexdec($matches[1]));
},
$string
);
Basically you just have to make three steps:
Upvotes: 4
Reputation: 127
according to PHP documentation http://php.net/manual/en/reference.pcre.pattern.modifiers.php the 'e' modifier is deprecated from version 5.5.0 and is removed from PHP 7 , so if you are considering upgrade to PHP 7 you should replace your code to something similar to the documentation or an answer like @Eydamos provided
Upvotes: -1