php 中有個(gè) strip_tags 函數(shù)可以方便地去除 HTML 標(biāo)簽。
用法如下:
echo strip_tags($html); // 去除 $html 中的 HTML、XML 以及 PHP 的標(biāo)簽。
例如:
$html = '<div id="test"><span>www.anddd.com</span></div>'; echo strip_tags($html);//將會(huì)輸出www.anddd.com
對(duì)于非標(biāo)準(zhǔn)的 HTML 代碼也能正確的去除:
echo strip_tags('<a href="www.php.cn"></a>'); //輸出 www.php.cn
相關(guān)參考:php中文網(wǎng)