减少php中段落的返回中断

时间:2012-08-07 01:18:48

标签: php preg-replace

这是变量:

$letexts = "Hello this is a sample


after 2 return breaks there is ...



another 3 return breaks";

正如你所看到的,有2个回归休息,然后是3回程休息。 我希望能够得到这样的结果:

echo $letexts;

将显示:

Hello this is a sample

after 2 return breaks there is ...

another 3 return breaks

我使用了所有这些并且没有工作,所以它让我拉我的头发:

$letexts = preg_replace("/\r\n\s*\r\n/", "\r\n", $letexts);
$letexts = str_replace(array("\r", "\n", "\r\n"), "\r\n", $letexts);
$letexts = trim($letexts);
$letexts = preg_replace('~[\r\n]~','',$letexts);

有什么建议吗?

2 个答案:

答案 0 :(得分:2)

如果要以html显示。

使用功能nl2br

答案 1 :(得分:0)

试试这个:

$letexts = preg_replace("/[\r\n]{3,}/", "\r\n\r\n", $letexts);