# str\_replace line breaks with \<p\> paragraph tags

**URL:** <https://forum.kirupa.com/t/str-replace-line-breaks-with-p-paragraph-tags/136210>\
**Category:** Uncategorized\
**Created:** [February 3, 2005, 1:56am UTC](https://forum.kirupa.com/t/str-replace-line-breaks-with-p-paragraph-tags/136210 "2005-02-03T01:56:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![polishbroadcast](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@polishbroadcast](https://forum.kirupa.com/u/polishbroadcast)\
**Post date:** [February 3, 2005, 1:56am UTC](https://forum.kirupa.com/t/str-replace-line-breaks-with-p-paragraph-tags/136210/1 "2005-02-03T01:56:12Z")

</div>

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:

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

```

It takes some text like this:

```auto
One line
 
Second line

Third line

```

and makes this:

```auto
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.
