php 去掉标签,空格和换行 类似simple_html_dom.php的作用

时间:2018-12-06 13:11:50   收藏:0   阅读:182

function DeleteHtml(){

//清除空格和换行
$str = trim($str); //清除字符串两边的空格
$str = strip_tags($str,""); //利用php自带的函数清除html格式
$str = preg_replace("/\t/","",$str); //使用正则表达式替换内容,如:空格,换行,并将替换为空。
$str = preg_replace("/\r\n/","",$str);
$str = preg_replace("/\r/","",$str);
$str = preg_replace("/\n/","",$str);
$str = preg_replace("/ /","",$str);
$str = preg_replace("/ /","",$str); //匹配html中的空格
return trim($str);

}

$a = DeleteHtml($str);
echo highlight_string($a);

效果如下(去掉标签):

技术分享图片

原文:https://www.cnblogs.com/ayanboke/p/10075973.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!