php使用strip_tags()去除html标签仍有空白

php使用strip_tags()方法去除html有空白的解决办法

$content = '<div><br /><strong>这是一段带有html标签的文字</strong></div><div><br />文章内容文章内容文章内容文章内容文章内容</div>';
$subject = strip_tags($content); //去除标签
$pattern = '/s/';//去除空白 //正则匹配空格
$content = preg_replace($pattern, '', $subject); //替换掉空格
$data = mb_substr($content, 0, 800);//截取100个汉字

原文地址:https://www.cnblogs.com/mayg/p/13955115.html