0

I am re doing an old project at work and getting a ton of these:

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

Looking at line 74:

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

How can I convert that to use the new call back?

Lovelock
  • 7,689
  • 19
  • 86
  • 186

1 Answers1

2

Easily.

$str = preg_replace_callback('/&#(\d+);/', function($m) use ($lo) {
    return code2utf($m[1],$lo);
}, $str);

The important thing here is the use ($lo), as it allows you to "import" the $lo variable into your callback.

I've also cleaned up your regex - way too many backslashes ;)

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592