php – 不推荐使用:preg_replace():不推荐使用/ e修饰符,而是
发布时间:2020-12-13 13:27:27 所属栏目:PHP教程 来源:网络整理
导读:我需要一些帮助.因为不推荐使用preg_replace,所以我必须将所有preg_replace转换为preg_replace_callback … 我尝试过的: 更改: $template = preg_replace ( "#[aviable=(.+?)](.*?)[/aviable]#ies","$this-check_module('1','2')",$template
我需要一些帮助.因为不推荐使用preg_replace,所以我必须将所有preg_replace转换为preg_replace_callback …
我尝试过的: 更改: $template = preg_replace ( "#[aviable=(.+?)](.*?)[/aviable]#ies","$this->check_module('1','2')",$template ); 至: $template = preg_replace_callback ( "#[aviable=(.+?)](.*?)[/aviable]#isu",return $this->check_module($this['1'],$this['2']); $template ); 错误: Parse error: syntax error,unexpected 'return'
callback需要是一个带有一个参数的函数,这是一个匹配数组.您可以通过任何类型的
callback,包括
anonymous function.
$template = preg_replace_callback( "#[aviable=(.+?)](.*?)[/aviable]#isu",function($matches) { return $this->check_module($matches[1],$matches[2]); },$template ); (为了在匿名函数中使用$this,需要PHP> = 5.4.0) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |