Home  >  Article  >  Backend Development  >  Detailed explanation of php's native function for removing html tags, detailed explanation of php tag function_PHP tutorial

Detailed explanation of php's native function for removing html tags, detailed explanation of php tag function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:08:51848browse

Detailed explanation of PHP’s native function for removing HTML tags, detailed explanation of PHP tag function

strip_tags removes HTML and PHP tags. Syntax: string strip_tags(string str); Return value: String Function type: Data processing Content description This function can remove any HTML and PHP tag strings contained in the string. If the HTML and PHP tags of the string are originally wrong, for example, the greater than symbol is missing, an error

will also be returned.

strip_tags

Remove HTML and PHP tags.

Syntax: string strip_tags(string str);

Return value: string

Function type: Data processing

Content description

This function can remove any HTML and PHP tag strings contained in the string. If the HTML and PHP tags of the string are originally wrong, for example, the greater than symbol is missing, an error will also be returned. This function has the same function as fgetss().

htmlspecialchars

Convert special characters into HTML format.

Syntax: string htmlspecialchars(string string);

Return value: string

Function type: Data processing

This function converts special characters into HTML string format ( &....; ). The most commonly used occasion may be the message board for processing customer messages.

 & (and) is converted to &
" (double quotation mark) is converted to "
​< (less than) is converted into <
> (greater than) is converted to >
This function only converts the above special characters, and does not convert all of them into the ASCII conversion specified by HTML.

Usage Example

Copy code The code is as follows:

$new = htmlspecialchars("Test", ENT_QUOTES);
echo $new;
?>

Attach an application example in my project:

MySQL database will escape special symbols when storing them in the database, and they will be escaped when we read them. However, my project needs to remove the HTML tags from the content in the n_info field first, and then intercept 60 characters. The content is displayed

I thought it could be achieved by directly using strip_tags(). However, when I actually used it, I found that because the content in the database was escaped, strip_tags could not be recognized, so I needed to convert the special characters first. Yi is back,

Specific code: _substr(strip_tags(htmlspecialchars_decode($value['n_info'])), 0, 60)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/948409.htmlTechArticleDetailed explanation of PHP’s native function to remove HTML tags, detailed explanation of PHP tag function strip_tags to remove HTML and PHP tags. Syntax: string strip_tags(string str); Return value: String Function type: Data...
Statement:
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