$str =preg_replace ("/\s+/", "", $str); Filter excess carriage return $str=preg_replace ("/<[]+/si", "<", $str); Filter <__ (with spaces behind "<") $str =preg_replace ("/<\!--. *?-->/si", "", $str); Note $str=preg_replace ("/< (\!. *?) >/si "," ", $str); Filter Doctype$str=preg_replace ("/< (\/?html.*?) >/si "," ", $str); Filter HTML Tags $str=preg_replace ("/< (\/?head.*?) >/si "," ", $str); Filter head tag $str=preg_replace ("/< (\/?meta.*?) >/si "," ", $str); Filter META tag $str=preg_replace ("/< (\/?body.*?) >/si "," ", $str); Filter body tag $str=preg_replace ("/< (\/?link.*?) >/si "," ", $str); Filter Link label $str=preg_replace ("/< (\/?form.*?) >/si "," ", $str); Filter Form label $str=preg_replace ("/cookie/si", "Cookie", $str); Filter Cookie Tags $str =preg_replace ("/< (applet.*?) > (. *?) < (\/applet.*?) >/si "," ", $str); Filter Applet label $str=preg_replace ("/< (\/?applet.*?) >/si "," ", $str); Filter applet Tags $str =preg_replace ("/< (style.*?) > (. *?) < (\/style.*?) >/si "," ", $str); Filter style label $str=preg_replace ("/< (\/?style.*?) >/si "," ", $str); FilterStyle label $str =preg_replace ("/< (title.*?) > (. *?) < (\/title.*?) >/si "," ", $str); Filter title Tag $str=preg_replace ("/< (\/?title.*?) >/si "," ", $str); Filter the title tag $str =preg_replace ("/< (object.*?) > (. *?) < (\/object.*?) >/si "," ", $str); Filter the OBJECT tag $str=preg_replace ("/<" (\/?objec.*?) >/si "," ", $str); Filter the OBJECT tag $str =preg_replace ("/< (noframes.*?) > (. *?) < (\/noframes.*?) >/si "," ", $str); Filter noframes label $str=preg_replace ("/< (\/?noframes.*?) >/si "," ", $str); Filter Noframes Tags $str =preg_replace ("/< (i?frame.*?) > (. *?) < (\/i?frame.*?) >/si "," ", $str); Filter Frame label $str=preg_replace ("/< (\/?i?frame.*?) >/si "," ", $str); Filter Frame label $str =preg_replace ("/< (script.*?) > (. *?) < (\/script.*?) >/si "," ", $str); Filter the script tag $str=preg_replace ("/< (\/?script.*?) >/si "," ", $str); Filter the script tag $str=preg_replace ("/javascript/si", "JavaScript", $STR); Filter the script tag $str=preg_replace ("/vbscript/si", "VBScript", $STR); Filter the script tag $str=preg_replace ("/on ([a-z]+) \s*=/si", "on\\1= ", $STR); Filter the script tag $str=preg_replace ("/&#/si", "the", $str); Filter script tags, such as Javascript:alert (
Clear spaces, line breaks
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);}
Filtering HTML Properties
1, filter the regular expression of all HTML tags:
</? [^>]+>//filter The regular expression for properties of all HTML tags: $html = preg_replace ("/< ([a-za-z]+) [^>]*>/", "<\\1>", $html);
PHP filter HTML tags, attributes, etc. regular expression summary