《PHP教程:php過濾HTML標簽、屬性等正則表達式匯總》要點:
本文介紹了PHP教程:php過濾HTML標簽、屬性等正則表達式匯總,希望對您有用。如果有疑問,可以聯系我們。
$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標簽 $str=preg_replace("/<(\/?head.*?)>/si","",$str); //過濾head標簽 $str=preg_replace("/<(\/?meta.*?)>/si","",$str); //過濾meta標簽 $str=preg_replace("/<(\/?body.*?)>/si","",$str); //過濾body標簽 $str=preg_replace("/<(\/?link.*?)>/si","",$str); //過濾link標簽 $str=preg_replace("/<(\/?form.*?)>/si","",$str); //過濾form標簽 $str=preg_replace("/cookie/si","COOKIE",$str); //過濾COOKIE標簽 ? $str=preg_replace("/<(applet.*?)>(.*?)<(\/applet.*?)>/si","",$str); //過濾applet標簽 $str=preg_replace("/<(\/?applet.*?)>/si","",$str); //過濾applet標簽 ? $str=preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si","",$str); //過濾style標簽 $str=preg_replace("/<(\/?style.*?)>/si","",$str); //過濾style標簽 ? $str=preg_replace("/<(title.*?)>(.*?)<(\/title.*?)>/si","",$str); //過濾title標簽 $str=preg_replace("/<(\/?title.*?)>/si","",$str); //過濾title標簽 ? $str=preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si","",$str); //過濾object標簽 $str=preg_replace("/<(\/?objec.*?)>/si","",$str); //過濾object標簽 ? $str=preg_replace("/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si","",$str); //過濾noframes標簽 $str=preg_replace("/<(\/?noframes.*?)>/si","",$str); //過濾noframes標簽 ? $str=preg_replace("/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si","",$str); //過濾frame標簽 $str=preg_replace("/<(\/?i?frame.*?)>/si","",$str); //過濾frame標簽 ? $str=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$str); //過濾script標簽 $str=preg_replace("/<(\/?script.*?)>/si","",$str); //過濾script標簽 $str=preg_replace("/javascript/si","Javascript",$str); //過濾script標簽 $str=preg_replace("/vbscript/si","Vbscript",$str); //過濾script標簽 $str=preg_replace("/on([a-z]+)\s*=/si","On\\1=",$str); //過濾script標簽 $str=preg_replace("http://si","&#",$str); //過濾script標簽,如alert(
清除空格,換行PHP實例
function DeleteHtml($str) { $str = trim($str); $str = strip_tags($str,""); $str = ereg_replace("\t","",$str); $str = ereg_replace("\r\n","",$str); $str = ereg_replace("\r","",$str); $str = ereg_replace("\n","",$str); $str = ereg_replace(" "," ",$str); return trim($str); }
過濾HTML屬性PHP實例
1,過濾所有html標簽的正則表達式:
PHP實例
PS:關于正則,這里再為大家保舉2款非常方便的正則表達式工具供大家參考使用:PHP實例
《PHP教程:php過濾HTML標簽、屬性等正則表達式匯總》是否對您有啟發,歡迎查看更多與《PHP教程:php過濾HTML標簽、屬性等正則表達式匯總》相關教程,學精學透。維易PHP學院為您提供精彩教程。