Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace preg_replace() to preg_replace_callback() [duplicate]

$source = preg_replace('/&#(\d+);/me', "utf8_encode(chr(\\1))", $source);

The above code gives deprecated warning.

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

How can I replace preg_replace() to preg_replace_callback() ?

like image 318
memmedimanli Avatar asked Jan 10 '23 15:01

memmedimanli


1 Answers

Read the documentation here, http://www.php.net/manual/en/function.preg-replace-callback.php

Here is an example of preg_replace_callback

$source = preg_replace_callback('/&#(\d+);/m', function($matches){
   return utf8_encode(chr($matches[1]));
}, $source);
like image 54
Rob M. Avatar answered Jan 21 '23 10:01

Rob M.