Remove HTML tags from PHP. We usually use htmlspecialchars () to filter html, but escape the html characters and display the html source code. use strip_tags () to remove html tags. zookeeper
We usually use htmlspecialchars () to filter html, but escape the html characters and display the html source code.
Use strip_tags () to remove html tags.
$ Str = 'href ';
// Echo htmlspecialchars ($ str );
Echo strip_tags ($ str );
?>
Many websites have a small part of an article on the homepage. here, we need to use strip_tags () to remove the html tag. however, we still need to consider the encoding of Chinese characters, because it is easy to cut the last Chinese character into half by cutting the field string normally.
/**
* Intercepting UTF-8 strings
* @ Since 2008.12.23
* @ Param string $ string intercepted by str
* @ Param integer $ start position
* @ Param integer $ length (each Chinese character is 3 bytes)
*/
Function utf8_strcut ($ str, $ start, $ length = null ){
Preg_match_all ('/./us', $ str, $ match );
$ Chars = is_null ($ length )? Array_slice ($ match [0], $ start): array_slice ($ match [0], $ start, $ length );
Unset ($ str );
Return implode ('', $ chars );
}
Escape () is used to filter html, but the html characters are escaped. the html source code is displayed. the html tag can be removed using strip_tags ....