PHP7.0废弃preg_replace后怎么调整
本文介绍了PHP7.0废弃preg_replace后怎么调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
$options = Typecho_Widget::widget('Widget_Options');
$sUrl = str_ireplace('/', '\/', rtrim($options->siteUrl, '/'));
$preg = '#(<a .*?href=")(?!' . $sUrl . ')([^"]+)"(.*?<\/a>)#ise';
$text = preg_replace($preg, "stripslashes('$1') . '$options->siteUrl' . 'go.html?url=' . base64_encode('$2') . '\" target=\"_blank\"' . stripslashes('$3')", $text);
代码放到PHP7.0后报错了,根据提示得知是preg_replace被废弃了,得用preg_replace_callback代替。请问怎么做?
解决方案
不是preg_replace被废弃,是/e这个修饰符被废弃。
我想大概应该这样改
preg_replace_callback($preg,
function ($matches) {
return stripslashes($matches[1]).$options->siteUrl.'go.html?url='.base64_encode($matches[2]).'\" target=\"_blank\"'.stripslashes($matches[3]);
});
这篇关于PHP7.0废弃preg_replace后怎么调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文