php 去掉html中的空格和换行的方法

发布时间:2022-07-02 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php 去掉html中的空格和换行的方法脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

 

 

/*
+----------------------------------------------------------
 * 去掉html中的空格和换行的方法
+----------------------------------------------------------
 */
function delhtml($str)
{
    $str = trim($str); //清除字符串两边的空格
    $str = strip_tags($str,""); //利用php自带的函数清除html格式
    $str = preg_replace("/t/","",$str); //使用正则表达式替换内容,如:空格,换行,并将替换为空。
    $str = preg_replace("/rn/","",$str);
    $str = preg_replace("/r/","",$str);
    $str = preg_replace("/n/","",$str);
    $str = preg_replace("/ /","",$str);
    $str = preg_replace("/  /","",$str);  //匹配html中的空格
    $str = preg_replace('# #','',$str);
    $str = preg_replace('/s+/u', '',$str);
    $str = preg_replace("/[sv".chr(163).chr(160)."]+$/","",$str);
    $str = str_replace(array(" "," ","t","n","r"," "), '', $str);
    $str = str_replace(chr(194) . chr(160), "-", $str);
    return trim($str); //返回字符串
}

可以去掉word导入的内容中的空格喔。

 

脚本宝典总结

以上是脚本宝典为你收集整理的php 去掉html中的空格和换行的方法全部内容,希望文章能够帮你解决php 去掉html中的空格和换行的方法所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: