PHP filter HTML tags, attributes, etc. regular expression summary

Source: Internet
Author: User
Tags script tag

$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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.