如何识别每个换行符?

时间:2010-07-13 22:59:35

标签: php

我怎么能识别每个换行符?它没有把>在每一条新线上。

我目前使用此'> ' . str_replace("\n", "\n> ", $msg);

输出:

[i]Originally posted by DiSanti[/i]
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
> Morbi in nunc vitaemauris.      
semper posuere sed nec metus. Phasellus fermentum mattis convallis. Integer   
nuncelit.    
vestibulum a hendrerit in, volutpat eu arcu. Nulla aliquet, leo 
acscelerisque.            

我希望它看起来像:

[i]Originally posted by DiSanti[/i]
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
> Morbi in nunc vitaemauris.     
> semper posuere sed nec metus. Phasellus fermentum mattis convallis. Integer   
> nuncelit.    
> vestibulum a hendrerit in, volutpat eu arcu. Nulla aliquet, leo 
> acscelerisque.            

1 个答案:

答案 0 :(得分:1)

问题是没有换行符。您可以强制使用最大行数而不会破坏wordwrap的单词。

尝试类似的事情;

$t = explode("\n", wordwrap($orig));
$t = array_map(function ($line) { return "&gt; $line<br />"; }, $t);
$final = implode("\n", $t);