Forum Moderators: coopster
<?php
function nls2p($str)
{
return str_replace('<p></p>', '', '<p>'
. preg_replace('#([\r\n]\s*?[\r\n]){2,}#', '</p>$0<p>', $str)
. '</p>');
}echo nl2br(nls2p("Paragraph1\n\nParagraph2\n line1\n line2\n"));
?>
I'm using it on a textarea and for some reason I'm getting both the <p> tags and ALL of the <br> tags so instead of \n\n turning into a paragraph it's turning into a paragraph with two breaks. Is the nls2p function not killing off the \n's that it's supposed to be replacing? I'm open to using another function in place of this, this just seemed to be the easiest I'd found.