Replacing </br> with <p> tags


php-code:

function nl2p( $str ) {
$str = str_replace( array("\r\n", "\r"), "\n", $str );
return "<p>\n" . str_replace( "\n", "\n</p>\n<p>\n", $str ) . "\n</p>";
}

$html = <<<HTML
This is some text we want to convert
line
breaks
to paragraph
tags
HTML;

echo nl2p( $html );

output:

<p>
This is some text we want to convert
</p>
<p>
line
</p>
<p>
breaks
</p>
<p>
to paragraph
</p>
<p>
tags
</p>