carlholmberg / mpdf

GNU General Public License v2.0
3 stars 12 forks source link

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

Open onkar-infoobjects opened 11 years ago

onkar-infoobjects commented 11 years ago

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 commented 11 years ago

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 commented 10 years ago

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

rzds commented 9 years ago

$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 commented 8 years ago

Thanks rzds

By use this my error is solved.

Thanks again!!

ikissiva commented 7 years ago

Hi guys,

Can you help me convert this to using preg_replace_callback

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

RalphCorderoy commented 7 years ago

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 commented 7 years ago

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

uistacks commented 6 years ago

Hi guys,

Can you help me convert this to using preg_replace_callback

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

ppavan1956 commented 3 years ago

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

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