正则,去掉onclick
$str = '<img src="http://www.kerehou.com/attachment/photo/Mon_1205/1265_5d971336976610640809cc1dfe218.jpg" border="0" onclick="if(this.parentNode.tagName!=\'A\'&&this.width>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"
这样就好了吧