Home > Backend Development > PHP Tutorial > php remove redundant HTML tags

php remove redundant HTML tags

WBOY
Release: 2016-07-25 08:56:34
Original
1162 people have browsed it
  1. echo strip_tags($str);
Copy the code

2. If you want to keep only

one tag, you only need to write the

string to the second parameter of strip_tags.

  1. echo strip_tags($str, "

    ");

Copy code

3. To retain

and ... multiple tags, just separate the multiple tags with spaces. 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() are generally used when entering and exiting the database to avoid storing keywords like quotation marks in variables. In this case, the part that is originally the content is recognized as an identifier by the database and executed, which will cause Error.

The htmlspecialchars() function is only used to escape a small amount of HTML, &, double quotation marks, greater than sign and less than sign. Not all of them will be converted into the ASCII conversion specified by HTML

htmlentities() This function is a bit like the htmlspecialchars() function, but this function will convert all string characters into HTML special character set strings. However, after the conversion, when reading the source code of the web page, especially the Chinese characters in the source code of the web page, the display will be abnormal when browsing, so please pay attention to this. Articles you may be interested in: Two methods to remove html tags in php Usage examples of php function strip_tags for filtering html tags (pictures and text) Three ways to delete html tags in php php deletes html tags and the code of html tags in strings Analysis of the difference between strip_tags and htmlspecialchars in removing html tags with php php function to delete html tags in string Remove the code of html tags in the content Extract php code of html tag Code examples of php regular filtering html tags, spaces, newlines, etc. php removes html tags to obtain input plain text document strip_tags php makes HTML tags automatically complete the code of the closing function php code to implement automatic completion of html tags How to use thinkPHP’s Html template tag



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template