Orlo
Orlo

Reputation: 828

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

I need a little help. Because preg_replace is deprecated, I have to convert all my preg_replace to preg_replace_callback...

What I've tried:

Change:

$template = preg_replace ( "#\\[aviable=(.+?)\\](.*?)\\[/aviable\\]#ies", "\$this->check_module('\\1', '\\2')", $template );

To:

$template = preg_replace_callback ( "#\\[aviable=(.+?)\\](.*?)\\[/aviable\\]#isu", 
                return $this->check_module($this['1'], $this['2']);
            $template );

Error:

Parse error: syntax error, unexpected 'return' 

Upvotes: 8

Views: 30024

Answers (1)

rid
rid

Reputation: 63442

The callback needs to be a function taking one parameter which is an array of matches. You can pass any kind of callback, including an anonymous function.

$template = preg_replace_callback(
    "#\\[aviable=(.+?)\\](.*?)\\[/aviable\\]#isu",
    function($matches) {
        return $this->check_module($matches[1], $matches[2]);
    },
    $template
);

(PHP >= 5.4.0 required in order to use $this inside the anonymous function)

Upvotes: 9

Related Questions