Well, it seems that you are considering a paragraph separator, an empty line. Thus, the simplest solution is as follows:
$text = str_replace( "\r", "", $text );
$lines = explode( "\n", $text );
$textResult = "";
foreach( $lines AS $line )
{
if( trim( $line ) == "" ) $textResult .= "<br />";
$textResult .= " " . $line;
}
I think this solves your problem. $textResultwill have your result
source
share