21,887
社区成员
发帖
与我相关
我的任务
分享
/**
* 去掉字符串的html标签
*
* @param string $str 包含html代码的字符串
* @return $text 去掉html标签后的纯洁字符串
*/
function html2txt($str)
{
$search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA
);
$text = preg_replace($search, '', $str);
return $text;
}