1

How could I recognize every linebreak? It doesnt put > on every new line.

I currently use this '> ' . str_replace("\n", "\n> ", $msg);

Output:

[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 want it to look like:

[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.            
DiSanti
  • 13
  • 2
  • str_replace("\n", "
    ", $msg); if it is for HTML and you already have the text with \n it will make it look like the what you want... it will not format the text for you, but only make it look like a new line where there is one.
    – Prix Jul 13 '10 at 23:03

1 Answers1

1

The problem is the line breaks aren't there. You can force a maximum line size without breaking words with wordwrap.

Try something like;

$t = explode("\n", wordwrap($orig));
$t = array_map(function ($line) { return "&gt; $line<br />"; }, $t);
$final = implode("\n", $t);
Artefacto
  • 96,375
  • 17
  • 202
  • 225