clh899 发表于 2015-8-30 12:16:53

PHP-preg_replace过滤字符串代码

$str=preg_replace("/\s+/", " ", $str); //过滤多余回车   
    $str=preg_replace(&quot;/<[ ]&#43;/si&quot;,&quot;<&quot;,$str); //过滤<__(&quot;<&quot;号后面带空格)   
    $str=preg_replace(&quot;/<\!--.*?-->/si&quot;,&quot;&quot;,$str); //注释   
    $str=preg_replace(&quot;/<(\!.*?)>/si&quot;,&quot;&quot;,$str); //过滤DOCTYPE   
    $str=preg_replace(&quot;/<(\/?html.*?)>/si&quot;,&quot;&quot;,$str); //过滤html标签   
    $str=preg_replace(&quot;/<(\/?head.*?)>/si&quot;,&quot;&quot;,$str); //过滤head标签   
    $str=preg_replace(&quot;/<(\/?meta.*?)>/si&quot;,&quot;&quot;,$str); //过滤meta标签   
    $str=preg_replace(&quot;/<(\/?body.*?)>/si&quot;,&quot;&quot;,$str); //过滤body标签   
    $str=preg_replace(&quot;/<(\/?link.*?)>/si&quot;,&quot;&quot;,$str); //过滤link标签   
    $str=preg_replace(&quot;/<(\/?form.*?)>/si&quot;,&quot;&quot;,$str); //过滤form标签   
    $str=preg_replace(&quot;/cookie/si&quot;,&quot;COOKIE&quot;,$str); //过滤COOKIE标签   
   
    $str=preg_replace(&quot;/<(applet.*?)>(.*?)<(\/applet.*?)>/si&quot;,&quot;&quot;,$str); //过滤applet标签   
    $str=preg_replace(&quot;/<(\/?applet.*?)>/si&quot;,&quot;&quot;,$str); //过滤applet标签   
   
    $str=preg_replace(&quot;/<(style.*?)>(.*?)<(\/style.*?)>/si&quot;,&quot;&quot;,$str); //过滤style标签   
    $str=preg_replace(&quot;/<(\/?style.*?)>/si&quot;,&quot;&quot;,$str); //过滤style标签   
   
    $str=preg_replace(&quot;/<(title.*?)>(.*?)<(\/title.*?)>/si&quot;,&quot;&quot;,$str); //过滤title标签   
    $str=preg_replace(&quot;/<(\/?title.*?)>/si&quot;,&quot;&quot;,$str); //过滤title标签   
   
    $str=preg_replace(&quot;/<(object.*?)>(.*?)<(\/object.*?)>/si&quot;,&quot;&quot;,$str); //过滤object标签   
    $str=preg_replace(&quot;/<(\/?objec.*?)>/si&quot;,&quot;&quot;,$str); //过滤object标签   
   
    $str=preg_replace(&quot;/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si&quot;,&quot;&quot;,$str); //过滤noframes标签   
    $str=preg_replace(&quot;/<(\/?noframes.*?)>/si&quot;,&quot;&quot;,$str); //过滤noframes标签   
    $str=preg_replace(&quot;/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si&quot;,&quot;&quot;,$str); //过滤frame标签   
    $str=preg_replace(&quot;/<(\/?i?frame.*?)>/si&quot;,&quot;&quot;,$str); //过滤frame标签   
    $str=preg_replace(&quot;/<(script.*?)>(.*?)<(\/script.*?)>/si&quot;,&quot;&quot;,$str); //过滤script标签   
    $str=preg_replace(&quot;/<(\/?script.*?)>/si&quot;,&quot;&quot;,$str); //过滤script标签   

    $str=preg_replace(&quot;/javascript/si&quot;,&quot;Javascript&quot;,$str); //过滤script标签   
    $str=preg_replace(&quot;/vbscript/si&quot;,&quot;Vbscript&quot;,$str); //过滤script标签   
    $str=preg_replace(&quot;/on(&#43;)\s*=/si&quot;,&quot;On\\1=&quot;,$str); //过滤script标签   
  $str=preg_replace(&quot;/&#/si&quot;,&quot;&#&quot;,$str); //过滤script标签,如javAsCript:alert('aabb)
  目前就会这些,恳请大牛指教~
页: [1]
查看完整版本: PHP-preg_replace过滤字符串代码