$pattern = array(
'//', // 替换smarty注释
'//', // 替换不换行的html注释
'/(href=["|'])../(.*?)(["|'])/i', // 替换相对链接
'/((?:background|src)s*=s*["|'])(?:./|../)?(images/.*?["|'])/is', // 在images前加上 $tmp_dir
'/((?:background|background-image):s*?url()(?:./|../)?(images/)/is', // 在images前加上 $tmp_dir
'/{nocache}(.+?){/nocache}/ise', //无缓存模块
);
$replace = array(
'',
'',
'',
'' . $tmp_dir . '',
'' . $tmp_dir . '',
"'{insert name="nocache" ' . '" . $this->_echash . "' . base64_encode('\1') . '}'",
);
return preg_replace($pattern, $replace, $source);
因为preg_replace被废弃了,使用preg_replace_callback替换应该怎么写啊?大侠指导一下好吗?
把有 /e 属性的拿出来单做
$source = preg_replace_callback( '/{nocache}(.+?){/nocache}/is', create_function('$r', "'{insert name="nocache" ' . '" . $this->_echash . "' . base64_encode($r[1]) . '}'"), $source);谢谢,我试一下。
/e 修正符使 preg_replace() 将 replacement 参数当作 PHP 代码(在适当的逆向引用替换完之后)
感谢您的回答。给分
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号