0

How it will look this using preg_replace_callback?

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

1 Answers1

0

If I am not mistaken you want to use preg_replace_callback instead of using the /e modifier.

If you want to pass extra parameters to the callback function you could make use of the use indentifier or wrap the callback in another function.

The second example could look like:

$str = preg_replace_callback(
    '/\&\#([0-9]+)\;/m', function ($matches) use ($lo) {
        // function body with return statement
}, $str
);

Notes

Your regex \&\#([0-9]+)\; will match a string like 𸽵. I think you don't have to ecape the & and #.

In your code you use return strtoupper($matches[1], $lo); but strtoupper takes one parameter instead of 2 parameters.

If this is what you want to match, then when running your code you could see that $matches[1] contains "233333" so this will be called return strtoupper("233333");

The fourth bird
  • 154,723
  • 16
  • 55
  • 70