Remove HTML tags in PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:28:28
Original
840 people have browsed it



Usually we use htmlspecialchars() to filter html, but after escaping the characters of html, what is finally displayed is the html source code.

Use strip_tags() to remove html tags.

$str = 'href';
//echo htmlspecialchars($str);
echo strip_tags($str);

?>

Many website homepages have a small part of an article. Here we need to use strip_tags() to remove the html tag. But for Chinese characters, we also need to consider what encoding is used, because it is easy to cut the field string normally and the last A Chinese character cut in half.

/**
* Intercept utf-8 string
* @since 2008.12.23
* @param string $str The intercepted string
* @param integer $start starting position
* @param integer $length interception 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);
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/788518.htmlTechArticleWe usually use htmlspecialchars() to filter html, but the html characters are escaped and finally displayed It is the html source code. Use strip_tags() to remove the html tags....
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!