-2

I am getting

preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead

in one of the files in my application.

Near the below lines

   $str = preg_replace('/\&\#([0-9]+)\;/me', "code2utf('\\1',{$lo})",$str);
   $str = preg_replace('/\&\#x([0-9a-fA-F]+)\;/me', "codeHex2utf('\\1',{$lo})",$str);

How to convert the above preg_replace code to preg_replace_callback?

Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54
rji rji
  • 697
  • 3
  • 17
  • 37

1 Answers1

-1

Use anonymous functions

Check this answer Replace deprecated preg_replace /e with preg_replace_callback

Community
  • 1
  • 1
Anurag Verma
  • 485
  • 2
  • 12
  • I have written my above code as $str = preg_replace_callback( "/\&\#([0-9]+)\;/me", function($m) { return code2utf($m[1],{$lo}); }, $str ); $str = preg_replace_callback( "/\&\#x([0-9a-fA-F]+)\;/me", function($m) { return codeHex2utf($m[1],{$lo}); }, $str ); I couldn't find deprecated issue but the page is blank. Is this the way I have to use preg_replace_callback? – rji rji Oct 12 '15 at 06:19
  • Post the full code block – Anurag Verma Oct 12 '15 at 06:30
  • I have created a test block for your reference just have a look https://ideone.com/k1xE5T – Anurag Verma Oct 12 '15 at 06:53