This article mainly introduces the detailed explanation of native functions for php to remove html tags. For more information, see
This article mainly introduces the detailed explanation of native functions for php to remove html tags. For more information, see
Strip_tags removes HTML and PHP tags. Syntax: string strip_tags (string str); Return Value: string function type: Data Processing content description this function removes any HTML and PHP mark strings contained in the string. If the HTML and PHP tags of a string are incorrect, for example, if a greater symbol is missing, an error is returned.
Strip_tags
Remove HTML and PHP tags.
Syntax: string strip_tags (string str );
Return Value: String
Correspondence type: Data Processing
Description
This function removes any HTML and PHP tag strings contained in the string. If the HTML and PHP tags of a string are incorrect, for example, if there is less than the symbol, an error is returned. This function has the same function as fgetss.
Htmlspecialchars
Convert special characters to HTML format.
Syntax: string htmlspecialchars (string );
Return Value: String
Correspondence type: Data Processing
This function converts special characters into the string format of HTML (&....;). The most common use case may be the message board for handling customer messages.
& (And) &
"(Double quotation marks)"
<(Less than) to <
> (Greater than) to>
This function only converts the preceding special characters and does not convert all the characters to the ASCII conversion specified in HTML.
Example
The Code is as follows:
<? Php
$ New = htmlspecialchars ("Test", ENT_QUOTES );
Echo $ new;
?>
Attach an application instance in your project:
When saving the data to the database, the mysql database will escape the special characters, which will be escaped when we read the data. In my project, we need to remove the HTML tag from the content in the n_info field first, then, the 60-character content is captured and displayed.
I thought it could be achieved by using strip_tags () directly. In actual use, it was found that the content in the database was escaped and strip_tags could not be identified, so we need to escape the special characters first,
Code: _ substr (strip_tags (htmlspecialchars_decode ($ value ['N _ info']), 0, 60)