PHP Complete filter html,js,css and other tags _php tips

Source: Internet
Author: User
Tags html tags
I remember writing an article before.
PHP Effective Filter HTML tags, js code, CSS style tags:
Copy Code code as follows:

<?php
$str = Preg_replace ("@<script" (. *?) </script> @is "," ", $str);
$str = Preg_replace ("@<iframe" (. *?) </iframe> @is "," ", $str);
$str = Preg_replace ("@<style" (. *?) </style> @is "," ", $str);
$str = Preg_replace ("@<" (. *?) > @is "," ", $str);
?>

, all regular filters HTML tags, but today it is not good to use them. Why? Is that the tag is escaped. For example, this is <br on the page. But the source file appears like this: "--but we can still handle it, and first compile the contents back.
Copy Code code as follows:

$str = Htmlspecialchars_decode ($STR);

The function of Htmlspecialchars_decode is to convert the source file into a label like <>. And then ":
Copy Code code as follows:

$str = Preg_replace ("/<" (. *?) >/"," ", $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.