php正則過濾html標(biāo)簽、空格、換行符的代碼(附說明)
更新時間:2010年10月25日 10:44:46 作者:
最常用正則過濾代碼,能夠幫你過濾多余回車,注釋,html標(biāo)簽等。
復(fù)制代碼 代碼如下:
$str=preg_replace("/\s+/", " ", $str); //過濾多余回車
$str=preg_replace("/<[ ]+/si","<",$str); //過濾<__("<"號后面帶空格)
$str=preg_replace("/<\!--.*?-->/si","",$str); //注釋
$str=preg_replace("/<(\!.*?)>/si","",$str); //過濾DOCTYPE
$str=preg_replace("/<(\/?html.*?)>/si","",$str); //過濾html標(biāo)簽
$str=preg_replace("/<(\/?head.*?)>/si","",$str); //過濾head標(biāo)簽
$str=preg_replace("/<(\/?meta.*?)>/si","",$str); //過濾meta標(biāo)簽
$str=preg_replace("/<(\/?body.*?)>/si","",$str); //過濾body標(biāo)簽
$str=preg_replace("/<(\/?link.*?)>/si","",$str); //過濾link標(biāo)簽
$str=preg_replace("/<(\/?form.*?)>/si","",$str); //過濾form標(biāo)簽
$str=preg_replace("/cookie/si","COOKIE",$str); //過濾COOKIE標(biāo)簽
$str=preg_replace("/<(applet.*?)>(.*?)<(\/applet.*?)>/si","",$str); //過濾applet標(biāo)簽
$str=preg_replace("/<(\/?applet.*?)>/si","",$str); //過濾applet標(biāo)簽
$str=preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si","",$str); //過濾style標(biāo)簽
$str=preg_replace("/<(\/?style.*?)>/si","",$str); //過濾style標(biāo)簽
$str=preg_replace("/<(title.*?)>(.*?)<(\/title.*?)>/si","",$str); //過濾title標(biāo)簽
$str=preg_replace("/<(\/?title.*?)>/si","",$str); //過濾title標(biāo)簽
$str=preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si","",$str); //過濾object標(biāo)簽
$str=preg_replace("/<(\/?objec.*?)>/si","",$str); //過濾object標(biāo)簽
$str=preg_replace("/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si","",$str); //過濾noframes標(biāo)簽
$str=preg_replace("/<(\/?noframes.*?)>/si","",$str); //過濾noframes標(biāo)簽
$str=preg_replace("/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si","",$str); //過濾frame標(biāo)簽
$str=preg_replace("/<(\/?i?frame.*?)>/si","",$str); //過濾frame標(biāo)簽
$str=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$str); //過濾script標(biāo)簽
$str=preg_replace("/<(\/?script.*?)>/si","",$str); //過濾script標(biāo)簽
$str=preg_replace("/javascript/si","Javascript",$str); //過濾script標(biāo)簽
$str=preg_replace("/vbscript/si","Vbscript",$str); //過濾script標(biāo)簽
$str=preg_replace("/on([a-z]+)\s*=/si","On\\1=",$str); //過濾script標(biāo)簽
$str=preg_replace("/&#/si","&#",$str); //過濾script標(biāo)簽,如javAsCript:alert(
相關(guān)文章
關(guān)于php 接口問題(php接口主要也就是運用curl,curl函數(shù))
本篇文章是對php中的接口問題(php接口主要也就是運用curl,curl函數(shù))進行了詳細(xì)的分析介紹,需要的朋友參考下2013-07-07
php session實現(xiàn)多級目錄存放實現(xiàn)代碼
這篇文章主要介紹了php session實現(xiàn)多級目錄存放實現(xiàn)代碼,需要的朋友可以參考下2016-02-02
php中g(shù)etservbyport與getservbyname函數(shù)用法實例
這篇文章主要介紹了php中g(shù)etservbyport與getservbyname函數(shù)用法,以實例形式分析了getservbyport與getservbyname函數(shù)獲取server端的端口等信息的方法,需要的朋友可以參考下2014-11-11
PHP中UNIX時間戳和日期間的轉(zhuǎn)換與計算實例
這篇文章主要介紹了PHP中UNIX時間戳和日期間的轉(zhuǎn)換與計算實例,本文講解了將日期和時間轉(zhuǎn)變成UNIX時間戳、日期的計算等內(nèi)容,需要的朋友可以參考下2014-11-11

