<p onclick="javascript:alert(333);" onerror="javascript:alert(331)" onload="javascript:window.location.href=''">
test</p><a onload="javascript:alert(11);">test</a>怎么过滤掉标签内的这些js事件?
如果是完全匹配事件的话,事件太多了,列举起来比较麻烦。
我的想法是能不能过滤掉以 on 开头的属性,并且能过滤掉全部的事件。

解决方案 »

  1.   


    $html=<<<EOF
    <body contenteditable="true" onload="javascript:alert('111');" onclick="javascript:alert(fsdfsd)"> 
    EOF;$regList = "/(<.*?)\s+(on\w+)\s*?=\s*?[\"|\'].*?[\"|\']([^>]*?>)/is";while(preg_match($regList,$html))
    {
    //什么原因,不能一次性过滤完?
    $html = preg_replace($regList,'$1$3',$html);
    }
    不加while条件的话,一个标签只能过滤一个事件,这个是怎么回事?
      

  2.   

    为什么先判断一次是否存在,然后又替换?直接正则替换不好吗?而且你这样写,好像 preg_match_all 更合适