PHP removes redundant HTML tags

Source: Internet
Author: User
    1. echo Strip_tags ($STR);
Copy Code

2, keep only

A label, you just need to

The string is written to the second argument of Strip_tags.

    1. Echo strip_tags ($str, "

      ");

Copy Code

3, to keep

With the. Multiple labels, you only need to separate multiple labels with a space and write to the second parameter of Strip_tags.

    1. Echo strip_tags ($str, "

      ");

Copy Code

4, keep all tags, just escape with addslashes (), Stripslashes (), Htmlspecialchars (), Htmlentities (), NL2BR () and other functions.

Addslashes (), stripslashes () is generally used when entering the database and out of the library, so as to avoid the variables to store similar quotes in the keywords, so that the original content of the part is recognized as an identifier by the database to execute, it will cause errors.

The Htmlspecialchars () function is used only to escape a small amount of HTML, &, double quotes, greater than and less than. Does not convert all of the ASCII conversions that are set to HTML

Htmlentities () This function is a bit like the Htmlspecialchars () function, but this function will convert all string characters to the special character set string of HTML. However, after the conversion, reading the source code of the Web page, especially the Chinese characters in the source code of the page, will be displayed when browsing is not normal, this should be noted. You may be interested in the article: PHP two ways to remove HTML tags PHP filter HTML tags function strip_tags usage examples (graphic) PHP Delete HTML tags three ways to share PHP delete HTML tags and HTML tags in the code PHP The difference between strip_tags and htmlspecialchars to remove HTML tags PHP removes the HTML tag's function from the HTML tag in the contents of the code to remove HTML tags in PHP code PHP regular filter HTML tags, spaces, Code examples such as line breaks PHP remove HTML tags get input plain text document strip_tagsphp make HTML tag auto complement closed function code PHP implementation HTML tag Auto complement code thinkphp HTML template Tag use method

  • 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.