Page 1 of 1

Line breaks in dynamically created content

Posted: Wed Feb 23, 2011 12:07 pm
by Stacks
Hello,

I have a form that receives data from a <textarea>.

Example Data.

Code: Select all

Hi,

I am very interested in your website.

Can you please contact me at 666.777.6677.

That data is then stored in a mySQL database.

When I retrieve that data and I spit it back out into a <textarea>, all of the paragraphs/line breaks still render properly.

However when I spit out that data into a <p></p> there are no paragraph's or new lines. That data is rendered in a <p> tag like this

Hi, I am very interested in your website. Can you please contact me at 666.777.6677.

How can I spit it into a <p> tag and have it render with the paragraphs?

Re: Line breaks in dynamically created content

Posted: Sun Feb 27, 2011 12:33 am
by social_experiment
Take a look at nl2br()
The Manual wrote: string nl2br ( string $string [, bool $is_xhtml= true ] )
Returns string with '<br />' or '<br>' inserted before all newlines.