Php completely filters HTML, JS, CSS, and other labels _ PHP Tutorial

Source: Internet
Author: User
Php completely filters HTML, JS, CSS, and other labels. Remember to write an article in the past that filters html tags, js code, and css style tags effectively in php: Copy the code as follows :? Php $ strpreg_replace (@ script (.*?) Script @ is, $ str); $ str remember to write an article before
Php effectively filters html tags, js code, and css style tags:

The code is as follows:


$ Str = preg_replace ("@ $ Str = preg_replace ("@ is", "", $ str );
$ Str = preg_replace ("@ @ Is "," ", $ str );
$ Str = preg_replace ("@ <(. *?)> @ Is "," ", $ str );
?>


All are regular expressions used to filter HTML tags, but they are useless today. why ?? The tag is Escaped. for example
. This is displayed on the page. However, the source file is displayed as follows: "-- but we can still process it. first decompile all the content and then filter it out.

The code is as follows:


$ Str = htmlspecialchars_decode ($ str );


To use the htmlspecialchars_decode function, convert the source file to a tag like <>. then ":

The code is as follows:


$ Str = preg_replace ("/<(. *?)> /"," ", $ Str );

Php effectively filters html tags, js code, and css style tags: the code is as follows :? Php $ str = preg_replace ("@ script (.*?) /Script @ is "," ", $ str); $ str...

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.