加入收藏
您当前的位置:首页 > PHP

如何用php去掉多余的空行?

时间:2009-11-25 19:55:24  来源:  作者:

php中,$text出现空行时,如何去掉$text当中的多余的空行呢? 可以用PHP函数 preg_replace — 执行一个正则表达式的搜索和替换

方法如下:
$text = preg_replace("/(\r\n|\n|\r|\t)/i", '', $text);
如:

<?php
$text = " Buy cheap eyeglasses and save a lot.

   Now mamny people begin to order eyeglasses online .

  More and more people buy prescription eyeglasses online now. 
 
  Here let me share a glasses shop: http://www.cheapglasses123.com";
    $text = preg_replace("/(\r\n|\n|\r|\t)/i", '', $text);
    echo $text;
?>

运行这代码的结果:
Buy cheap eyeglasses and save a lot. Now mamny people begin to order eyeglasses online . More and more people buy prescription eyeglasses online now. Here let me share a glasses shop: http://www.cheapglasses123.com

特别说明:本站部分资源来源网络,仅供学习与参考,请勿用于商业用途。转载请注明来自:www.phpld.cn PHPL中文网
上一篇:很抱歉没有了
下一篇:十天学会php之第六天
推荐资讯
DedeCMS将data目录迁移到web根目录之外
DedeCMS将data目录迁移
相关信息
    无相关信息
头条信息
热门信息