str_replace line breaks with <p> paragraph tags

I have a light news-posting system which works fine but the original code translated line breaks in the text window to “<br>” tags in the html output. What i ultimately want is to have each paragraph surrounded by an opening and closing paragraph tag.

So i am close with this:

 $_POST['titletext'] = str_replace('</p><p>', "
", $_POST['titletext']);

It takes some text like this:

One line
 
Second line

Third line

and makes this:

One line</p><p></p><p>Second line<p></p><p>Third line

Which is close but it seems like it is replacing all instances of \r and
independently instead of
as a single entity. Can anyone assist? I know the secret password into heaven if you can.