Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead. This happens with php5.5 #1

Open
onkar-infoobjects opened this issue Jul 19, 2013 · 9 comments

Comments

@onkar-infoobjects
Copy link

preg_replace() has been used on line 79 & 80 but now in php5.5 it have been deprecated with preg_replace_callback(), what would be solution of this problem.

mpdf/includes/functions.php :: 79 & 80 line

75 if(!function_exists('strcode2utf')){
76 function strcode2utf($str,$lo=true) {
77 //converts all the &#nnn; and &#xhhh; in a string to Unicode
78 if ($lo) { $lo = 1; } else { $lo = 0; }
79 $str = preg_replace('/&#([0-9]+);/me', "code2utf('\1',{$lo})",$str);
80 $str = preg_replace('/&#x([0-9a-fA-F]+);/me', "codeHex2utf('\1',{$lo})",$str);
81 return $str;
82 }
83 }

@onkar-infoobjects
Copy link
Author

I have solved this issue by replacing line 79 & 80 by following code.

$str = preg_replace_callback('/&#([0-9]+);/m', function($m){ return code2utf($m[1],$lo); }, $str);
$str = preg_replace_callback('/&#([0-9]+);/m', function($m){ return codeHex2utf($m[1],$lo);}, $str);

@sandroneuhaus
Copy link

Had the same problem calling the library helper CodeIgniter and your solution worked properly. Thank you!

@rzds
Copy link

rzds commented Dec 5, 2014

$lo it's null inside that function.
"use" is required in order to make that variable available inside that function.

$str = preg_replace_callback('/\&\#([0-9]+)\;/m', function($m) use ($lo){return code2utf($m[1],$lo); }, $str);
$str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', function($m) use ($lo){return codeHex2utf($m[1],$lo);}, $str);

@ajay-patidar
Copy link

Thanks rzds

By use this my error is solved.

Thanks again!!

@ikissiva
Copy link

ikissiva commented Dec 7, 2016

Hi guys,

Can you help me convert this to using preg_replace_callback

preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':"$2";'", $input)

@RalphCorderoy
Copy link

Similar warnings occur for other lines.

$ cat -n MPDF57/mpdf.php | sed -n '7663p; 12058p'
  7663                  $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
 12058                  $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
$

@SuperNovaP
Copy link

This forgotten thread just saved me, thank you all haha. It works just fine!

@uistacks
Copy link

Hi guys,

Can you help me convert this to using preg_replace_callback

preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':"$2";'", $input)

@ppavan1956
Copy link

I can't seem to figure out the preg_replace_callback for the code below

$html = preg_replace('/{DATE\s+(.*?)}/e',"date('\1')",$html );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants