Replace preg_replace() to preg_replace_callback() [duplicate]
Asked Answered
A

2

5
$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() ?

Arrant answered 6/5, 2014 at 15:7 Comment(0)
M
8

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);
Magalimagallanes answered 6/5, 2014 at 15:42 Comment(0)
A
3
$source = preg_replace_callback
(
    '/\&\#(\d+)\;/m',
    function($match){
        return utf8_encode(chr($match[1]));
    },
    $source
);
Augend answered 6/5, 2014 at 15:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.