0

I am trying to replace this:

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

with preg_replace_callback and an anonymous function.

What would be the right way to do this?

kero
  • 10,647
  • 5
  • 41
  • 51
Sight
  • 27
  • 7

1 Answers1

1

Try the following:

preg_replace_callback(
    '/&#(\d+);/m',
    function ($matches) {
        return utf8_encode(chr($matches[1]));
    },
    $source
);
Lorenzo Marcon
  • 8,029
  • 5
  • 38
  • 63