我需要一些帮助.因为preg_replace已弃用,我必须全部转换my preg_replace为preg_replace_callback...
我尝试过的:
更改:
$template = preg_replace ( "#\\[aviable=(.+?)\\](.*?)\\[/aviable\\]#ies", "\$this->check_module('\\1', '\\2')", $template );
Run Code Online (Sandbox Code Playgroud)
至:
$template = preg_replace_callback ( "#\\[aviable=(.+?)\\](.*?)\\[/aviable\\]#isu",
return $this->check_module($this['1'], $this['2']);
$template );
Run Code Online (Sandbox Code Playgroud)
错误:
Parse error: syntax error, unexpected 'return'
Run Code Online (Sandbox Code Playgroud)
该回调必须采取一个参数,该参数是匹配的数组的函数.您可以传递任何类型的回调,包括匿名函数.
$template = preg_replace_callback(
"#\\[aviable=(.+?)\\](.*?)\\[/aviable\\]#isu",
function($matches) {
return $this->check_module($matches[1], $matches[2]);
},
$template
);
Run Code Online (Sandbox Code Playgroud)
(为了$this在匿名函数中使用,需要PHP> = 5.4.0 )
| 归档时间: |
|
| 查看次数: |
28844 次 |
| 最近记录: |