0

这是变量:

$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);

请问有什么建议吗?

4

2 回答 2

2

如果你想用html显示。

使用函数nl2br

于 2012-08-07T01:46:19.540 回答
0

试试这个:

$letexts = preg_replace("/[\r\n]{3,}/", "\r\n\r\n", $letexts);
于 2012-08-07T01:22:39.913 回答