Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

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' 
like image 653
Orlo Avatar asked Jan 24 '14 14:01

Orlo


1 Answers

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)

like image 120
rid Avatar answered Oct 15 '22 13:10

rid