Home >Backend Development >PHP Tutorial >正则,去掉onclick解决办法

正则,去掉onclick解决办法

WBOY
WBOYOriginal
2016-06-13 10:24:431690browse

正则,去掉onclick
$str = '正则,去掉onclick解决办法';

我想去掉上面字符串中的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"

这样就好了吧

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn