正则,去掉onclick
$str = '
screen.width-461) window.open('http://www.kerehou.com/attachment/photo/Mon_1205/1265_5d971336976610640809cc1dfe218.jpg');" >';
我想去掉上面字符串中的onclick,我写的正则如下:
function clear_onclick($document) {
if (!$document) return $document;
$search = array(
"/onclick=('|"|)?(.*)('|"|)/ismUe",
);
$replace = array( "",
);
$text = preg_replace($search,$replace,$document);
return $text;
}
echo clear_onclick($str);
貌似达不到我的效果,请教一下如何写正则去掉?
------解决方案--------------------
"/onclick=('|")?(.*)\1/sU"
这样就好了吧
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号