There is a strip_tags function in php that can easily remove HTML tags.
Usage is as follows:
echo strip_tags($html); // 去除 $html 中的 HTML、XML 以及 PHP 的标签。
For example:
$html = '<div id="test"><span>www.anddd.com</span></div>'; echo strip_tags($html);//将会输出www.anddd.com
Non-standard HTML codes can also be removed correctly:
echo strip_tags('<a href="www.php.cn"></a>'); //输出 www.php.cn
Related references: php中文网
The above is the detailed content of How to remove html tags in php. For more information, please follow other related articles on the PHP Chinese website!