How to fix preg_replace() errors in PHP 5.6 + 7.x for DJ AME's 2.5/2.7 :
- This fix is for the
preg_replace Errors (Error 1) in
ame_bbcode.php reported by user
Mandushi above.
- In my case I encountered the
2nd Error
(Error 2) seen below after upgrading to
vBulletin 3.8.1.1 and PHP 5.6+
Error 1: In vBulletin 3.8.x versions using PHP 5.6 +:
Code:
mod_fcgid: stderr: PHP Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /includes/ame_bbcode.php on line 712
Error 2: In vBulletin 3.8.1.1, when using PHP 5.6 +:
Code:
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in includes/ame_bbcode.php on line 331\n'
Here is the fix:
Thankfully I had some help to complete this fix long time a go on
StackOverflow (Credits Barmar). So the methods below below will fix all of the preg_replace deprecated errors in ame_bbcode.php file.
1. Edit the >
ame_bbcode.php and find this line in function named
(&fetch_full_ameinfo):
2. Then replace the
COMPLETE section with this instead:
Code:
if (!$findonly)
{
$ameinfo['find'][] = "~($result[findcode])~ie";
$ameinfo['replace'][] = 'ame_match_bbcode($param1, $param2, \'' . $result['ameid'] . '\', \'' . ame_slasher($result['title']) . '\', ' . $result['container'] . ', \'' . ame_slasher($result['replacecode']) . '\', \'$match[1]\', \'$match[2]\', \'$match[3]\', \'$match[4]\', \'$match[5]\', \'$match[6]\')';
}
else
{
$ameinfo['find'][] = "~(\[url\]$result[findcode]\[/url\])~ie";
$ameinfo['find'][] = "~(\[url="?$result[findcode]"?\](.*?)\[/url\])~i";
$ameinfo['replace'][] = 'ame_match("$match[1]", "", ' . intval($result['extraction']) .', "' . ($result['embedregexp'] ? "~" . ame_slasher($result['embedregexp']) . "~sim" : "") . '", "' . ($result['validation'] ? "~" . ame_slasher($result['validation']) . "~sim" : "") . '",$ameinfo)';
$ameinfo['replace'][] = 'ame_match("$match[1]", "$match[2]", ' . intval($result['extraction']) .', "' . ($result['embedregexp'] ? "~" . ame_slasher($result['embedregexp']) . "~sim" : "") . '", "' . ($result['validation'] ? "~" . ame_slasher($result['validation']) . "~sim" : "") . '", $ameinfo)';
}
3. Next find the line below in function named
function ame_process_bbcode:
Code:
$text = preg_replace($ameinfo['find'], $ameinfo['replace'], ($param2 ? $param2 : $param1), 1);
4. And replace it with this instead:
Code:
$text = preg_replace_callback($ameinfo['find'], function($match) use (&$param1, &$param2, &$ameinfo) {
return eval($ameinfo['replace']);
}, ($param2 ? $param2 : $param1), 1);
And that's pretty much it. Now you should no longer experince the preg_replace errors in
ame_bbcode.php
Additional Fix for line 324 in ame_bbcode.php
1. The line seen below at line 324 will also show up as a Deprecated Error:
Code:
$text = preg_replace($ameinfo['find'], $ameinfo['replace'], $text);
2. To fix it, just replace it with the line below as well:
Code:
$text = preg_replace($substitutes, $subhandlers, $text);
$text = preg_replace_callback($ameinfo['find'], function($match) use (&$text) {
return eval($ameinfo['replace']);
}, ($text), 1);
Please leave a feed back for others to know if you were able to make it work on your end. Thank you.
Regards China.