Reputation: 25
Can someone please help me with converting code
$file = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $file);
to use preg_replace_callback
instead of it ?
Thanks
Upvotes: 1
Views: 526
Reputation: 32532
$file = preg_replace_callback('~&#([0-9]+);~', function($m) { return chr($m[1]); }, $file);
If you are on a version of php that doesn't support anonymous functions, you can do this instead:
function myfunction($m) { return chr($m[1]); }
$file = preg_replace_callback('~&#([0-9]+);~', 'myfunction', $file);
Upvotes: 2
Reputation: 435
It might be something like this:
$file = preg_replace_callback(
'~&#([0-9]+);~',
function ($matches) {
// action
},
$file
);
PS. Without e modificator.
Upvotes: 0