<p>php正则过滤html标签、空格、换行符的代码(附说明) //过滤中文开始<br /> $str = &#39;7501yu1298中人bbce国yy2008&#39;;<br /> $par = &quot;/[x80-xff]/&quot;;<br /> echo preg_replace($par,&quot;&quot;,$str);//过滤中文结束</p> <p>$content=preg_replace(&quot;/s+/&quot;, &quot; &quot;, $content); //过滤多余回车</p> <p><br /> $content=preg_replace(&quot;/&lt;[ ]+/si&quot;,&quot;&lt;&quot;,$content); //过滤&lt;__(&quot;&lt;&quot;号后面带空格)</p> <p><br /> $content=preg_replace(&quot;/<!--.*?-->/si&quot;,&quot;&quot;,$content); //注释</p> <p><br /> $content=preg_replace(&quot;/&lt;(!.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤DOCTYPE</p> <p><br /> $content=preg_replace(&quot;/&lt;(/?html.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤html标签</p> <p><br /> $content=preg_replace(&quot;/&lt;(/?head.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤head标签</p> <p><br /> $content=preg_replace(&quot;/&lt;(/?meta.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤meta标签</p> <p><br /> $content=preg_replace(&quot;/&lt;(/?body.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤body标签</p> <p><br /> $content=preg_replace(&quot;/&lt;(/?link.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤link标签</p> <p><br /> $content=preg_replace(&quot;/&lt;(/?form.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤form标签</p> <p><br /> $content=preg_replace(&quot;/cookie/si&quot;,&quot;COOKIE&quot;,$content); //过滤COOKIE标签</p> <p><br /> $content=preg_replace(&quot;/&lt;(applet.*?)&gt;(.*?)&lt;(/applet.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤applet标签<br /> $content=preg_replace(&quot;/&lt;(/?applet.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤applet标签</p> <p><br /> $content=preg_replace(&quot;/&lt;(style.*?)&gt;(.*?)&lt;(/style.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤style标签<br /> $content=preg_replace(&quot;/&lt;(/?style.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤style标签</p> <p><br /> $content=preg_replace(&quot;/&lt;(title.*?)&gt;(.*?)&lt;(/title.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤title标签<br /> $content=preg_replace(&quot;/&lt;(/?title.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤title标签</p> <p><br /> $content=preg_replace(&quot;/&lt;(object.*?)&gt;(.*?)&lt;(/object.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤object标签<br /> $content=preg_replace(&quot;/&lt;(/?objec.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤object标签</p> <p><br /> $content=preg_replace(&quot;/&lt;(noframes.*?)&gt;(.*?)&lt;(/noframes.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤noframes标签<br /> $content=preg_replace(&quot;/&lt;(/?noframes.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤noframes标签</p> <p><br /> $content=preg_replace(&quot;/&lt;(i?frame.*?)&gt;(.*?)&lt;(/i?frame.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤frame标签<br /> $content=preg_replace(&quot;/&lt;(/?i?frame.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤frame标签</p> <p><br /> $content=preg_replace(&quot;/&lt;(script.*?)&gt;(.*?)&lt;(/script.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤script标签<br /> $content=preg_replace(&quot;/&lt;(/?script.*?)&gt;/si&quot;,&quot;&quot;,$content); //过滤script标签<br /> $content=preg_replace(&quot;/javascript/si&quot;,&quot;Javascript&quot;,$content); //过滤script标签<br /> $content=preg_replace(&quot;/vbscript/si&quot;,&quot;Vbscript&quot;,$content); //过滤script标签</p> <p></p>
T:0.008438s,M:207.59 KB
返回顶部 留言