Remove unnecessary HTML tags from php

Source: Internet
Author: User
Remove unnecessary HTML tags from php

  1. Echo strip_tags ($ str );

2. retain only

For a tag, you only need

The string is written to the second parameter of strip_tags.

  1. Echo strip_tags ($ str ,"

    ");

3. retain

And... Multiple tags, separated by spaces, must be written to the second parameter of strip_tags.

  1. Echo strip_tags ($ str ,"

    ");

4. keep all tags and only escape functions such as addslashes (), stripslashes (), htmlspecialchars (), htmlentities (), and nl2br.

Addslashes () and stripslashes () are generally used when the database is in and out of the warehouse, so as not to store keywords such as quotation marks in the variables. in this case, if a part of the content is recognized as an identifier by the database for execution, an error will occur.

The htmlspecialchars () function is only used to escape a small amount of HTML, &, double quotation marks, greater than or less than signs. it is not converted to the ASCII conversion specified in HTML.

Htmlentities () this function is a bit like the htmlspecialchars () function, but this function converts all string characters into special character set strings of HTML. However, when reading the source code of a web page, especially the text in the source code of a web page, it will be abnormal during browsing. Articles that you may be interested in: two methods for removing html tags by php: example of how php filters html tags using the strip_tags function (text) php: three methods for deleting html tags: php: code for deleting html tags from html tags and code for deleting html tags from strings: php: differences between strip_tags and htmlspecialchars analysis of removing html tags from string deletion functions by php html tag code extraction html tag php code php regular filter html tags, spaces, line breaks, and other code examples php remove html tags get input plain text document strip_tagsphp make HTML tags automatically closed function code php: how to use html template tags of code thinkPHP to automatically complete Html tags

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.