php正則過(guò)濾html標(biāo)簽、空格、換行符的代碼(附說(shuō)明)
更新時(shí)間:2010年10月25日 10:44:46 作者:
最常用正則過(guò)濾代碼,能夠幫你過(guò)濾多余回車(chē),注釋?zhuān)琱tml標(biāo)簽等。
復(fù)制代碼 代碼如下:
$str=preg_replace("/\s+/", " ", $str); //過(guò)濾多余回車(chē)
$str=preg_replace("/<[ ]+/si","<",$str); //過(guò)濾<__("<"號(hào)后面帶空格)
$str=preg_replace("/<\!--.*?-->/si","",$str); //注釋
$str=preg_replace("/<(\!.*?)>/si","",$str); //過(guò)濾DOCTYPE
$str=preg_replace("/<(\/?html.*?)>/si","",$str); //過(guò)濾html標(biāo)簽
$str=preg_replace("/<(\/?head.*?)>/si","",$str); //過(guò)濾head標(biāo)簽
$str=preg_replace("/<(\/?meta.*?)>/si","",$str); //過(guò)濾meta標(biāo)簽
$str=preg_replace("/<(\/?body.*?)>/si","",$str); //過(guò)濾body標(biāo)簽
$str=preg_replace("/<(\/?link.*?)>/si","",$str); //過(guò)濾link標(biāo)簽
$str=preg_replace("/<(\/?form.*?)>/si","",$str); //過(guò)濾form標(biāo)簽
$str=preg_replace("/cookie/si","COOKIE",$str); //過(guò)濾COOKIE標(biāo)簽
$str=preg_replace("/<(applet.*?)>(.*?)<(\/applet.*?)>/si","",$str); //過(guò)濾applet標(biāo)簽
$str=preg_replace("/<(\/?applet.*?)>/si","",$str); //過(guò)濾applet標(biāo)簽
$str=preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si","",$str); //過(guò)濾style標(biāo)簽
$str=preg_replace("/<(\/?style.*?)>/si","",$str); //過(guò)濾style標(biāo)簽
$str=preg_replace("/<(title.*?)>(.*?)<(\/title.*?)>/si","",$str); //過(guò)濾title標(biāo)簽
$str=preg_replace("/<(\/?title.*?)>/si","",$str); //過(guò)濾title標(biāo)簽
$str=preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si","",$str); //過(guò)濾object標(biāo)簽
$str=preg_replace("/<(\/?objec.*?)>/si","",$str); //過(guò)濾object標(biāo)簽
$str=preg_replace("/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si","",$str); //過(guò)濾noframes標(biāo)簽
$str=preg_replace("/<(\/?noframes.*?)>/si","",$str); //過(guò)濾noframes標(biāo)簽
$str=preg_replace("/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si","",$str); //過(guò)濾frame標(biāo)簽
$str=preg_replace("/<(\/?i?frame.*?)>/si","",$str); //過(guò)濾frame標(biāo)簽
$str=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$str); //過(guò)濾script標(biāo)簽
$str=preg_replace("/<(\/?script.*?)>/si","",$str); //過(guò)濾script標(biāo)簽
$str=preg_replace("/javascript/si","Javascript",$str); //過(guò)濾script標(biāo)簽
$str=preg_replace("/vbscript/si","Vbscript",$str); //過(guò)濾script標(biāo)簽
$str=preg_replace("/on([a-z]+)\s*=/si","On\\1=",$str); //過(guò)濾script標(biāo)簽
$str=preg_replace("/&#/si","&#",$str); //過(guò)濾script標(biāo)簽,如javAsCript:alert(
您可能感興趣的文章:
- php使用正則過(guò)濾js腳本代碼實(shí)例
- php過(guò)濾HTML標(biāo)簽、屬性等正則表達(dá)式匯總
- PHP過(guò)濾★等特殊符號(hào)的正則
- php 正則 過(guò)濾html 的超鏈接
- PHP中過(guò)濾常用標(biāo)簽的正則表達(dá)式
- PHP正則表達(dá)式過(guò)濾html標(biāo)簽屬性(DEMO)
- PHP使用正則表達(dá)式實(shí)現(xiàn)過(guò)濾非法字符串功能示例
- php正則刪除img標(biāo)簽的方法示例
- php正則刪除html代碼中class樣式屬性的方法
- phpstorm 正則匹配刪除空行、注釋行(替換注釋行為空行)
- PHP正則過(guò)濾處理微信昵稱中emoji字符的方法
相關(guān)文章
淺析HTTP消息頭網(wǎng)頁(yè)緩存控制以及header常用指令介紹
本篇文章是對(duì)HTTP消息頭網(wǎng)頁(yè)緩存控制以及header常用指令進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06PHP實(shí)現(xiàn)動(dòng)態(tài)創(chuàng)建XML文檔的方法
這篇文章主要介紹了PHP實(shí)現(xiàn)動(dòng)態(tài)創(chuàng)建XML文檔的方法,結(jié)合實(shí)例形式分析了php針對(duì)xml格式數(shù)據(jù)的構(gòu)建及文件讀寫(xiě)相關(guān)操作技巧,需要的朋友可以參考下2018-03-03PHP排序算法之堆排序(Heap Sort)實(shí)例詳解
這篇文章主要介紹了PHP排序算法之堆排序(Heap Sort),結(jié)合實(shí)例形式詳細(xì)分析了堆排序的原理、實(shí)現(xiàn)方法及相關(guān)使用注意事項(xiàng),需要的朋友可以參考下2018-04-04mysql_fetch_assoc和mysql_fetch_row的功能加起來(lái)就是mysql_fetch_array
mysql_fetch_assoc和mysql_fetch_row的功能加起來(lái)就是mysql_fetch_array...2007-01-01PHP strip_tags()去除HTML、XML以及PHP的標(biāo)簽介紹
這篇文章主要介紹了PHP strip_tags()去除HTML、XML以及PHP的標(biāo)簽介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-02-02Php連接及讀取和寫(xiě)入mysql數(shù)據(jù)庫(kù)的常用代碼
既然現(xiàn)在你看到了這篇文章,說(shuō)明你肯定知道PHP和MySQL是怎么一回事,我就不啰嗦了。但為什么你還要繼續(xù)閱讀此文呢?可能是以前你習(xí)慣復(fù)制粘貼一些代碼,并沒(méi)有真正弄懂代碼的含義;也可能你以前弄懂了,但像我一樣,有一段時(shí)間沒(méi)有接觸,生疏了2014-08-08