去除文章摘要中的空格和换行
最近查看源码发现了一个问题,在文章摘要的地方出现了许多换行和空格,看上去很不美观。影响代码整体的美观。我承认我有强迫症··
百度查了下找到以下的方法解决!
<?php //去除空格和换行 function DeleteHtml($str) { $str = trim($str); //清除字符串两边的空格 $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); //返回字符串 } ?>下面这副截图是使用前的样子。
这副图是使用后的样子。
是不是觉得简洁了许多,看上去舒服了许多,那就快来试试看吧!
- 版权申明:此文如未标注转载均为本站原创,自由转载请表明出处《IT技术宅》。
- 本文网址:https://www.ilt.me/dmfx/30.html
- 上篇文章:emlog短代码功能演示
- 下篇文章:爱情是什么?好暖的回答