替换PHP中的空行 [英] replace blank lines in php
本文介绍了替换PHP中的空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从字符串中删除多个空白行. 我查看了关于stackoverflow的示例,并尝试相应地更改了代码,但是我没有得到正确的答案.
How do I remove multiple blank lines from a string. I have looked at the examples on stackoverflow and have tried to change my code accordingly but I am not getting the right answer.
function removeMultipleBlankLines(&$array)
{
$value = $array;
$value = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $value);
return $value;
}
$textarray=array("The red","big"," "," ","fox","is ready","","","to jump.");
echo print_r(removeMultipleBlankLines($textarray));
推荐答案
您可以这样做:
$array_with_nonblank_lines = array_filter($textarray, 'trim');
获得您想要的东西.
此处是 php的有关trim
函数的文档页面的链接,该页面做这项工作.
Here is link to php's docs page about trim
function, which does the job.
这篇关于替换PHP中的空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文