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

I need a little help. Since preg_replace deprecated, I need to convert all my preg_replace to preg_replace_callback ...

What I tried:

Edit:

 $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 ); 

Mistake:

 Parse error: syntax error, unexpected 'return' 
+8
php
source share
1 answer

callback should be a function that takes 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 is required to use $this inside an anonymous function)

+8
source share

All Articles