i am unable to replacing preg_replace with preg_replace_callback, someone please do it for me

72 views Asked by At

I am installing phpfox script, after installation it is showing the following error,

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead - include/library/phpfox/setting/setting.class.php (321)

I have just got to the code and i am unable to change the syntax to preg_replace_callback

so i am writing the code below, kindly convert it for me thanks. 1

$aRow['value_actual'] = preg_replace("/s:(.*):\"(.*?)\";/ise", "'s:'.strlen('$2').':\"$2\";'", $aRow['value_actual']);

2

preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING']

3

preg_replace("/(.*?)\.(.*?)$/i", ".$2", $_SERVER['HTTP_HOST']

kindly convert 4th one as well.

4

preg_replace("/s:(.*):\"(.*?)\";/ise", "'s:'.strlen('$2').':\"$2\";'", (isset($aRow['user_group_id2']) && isset($aRow[$aRow['user_group_id']])) ? $aRow[$aRow['user_group_id']] : $aRow['value_actual']);
1

There are 1 answers

4
jh1711 On

2 and 3 don't have the e modifier. Nothing to do. For 1 use:

$aRow['value_actual'] = preg_replace_callback(
'/s:(.*):\"(.*?)\";/is',
function ($m) { return "s:".strlen($m[2]).':"'.$m[2].'";';},
$aRow['value_actual']);

If you want an explanation for any of them, please update your question. If you don't that's fine, too.

4

 preg_replace("/s:(.*):\"(.*?)\";/ise", "'s:'.strlen('$2').':\"$2\";'", 
 (isset($aRow['user_group_id2']) && isset($aRow[$aRow['user_group_id']])) ? 
 $aRow[$aRow['user_group_id']] : $aRow['value_actual']);

becomes:

 preg_replace("/s:(.*):\"(.*?)\";/is", 
 function ($m) { return "s:".strlen($m[2]).':"'.$m[2].'";';}, 
 (isset($aRow['user_group_id2']) && isset($aRow[$aRow['user_group_id']])) ? 
 $aRow[$aRow['user_group_id']] : $aRow['value_actual']);