Line breaks in dynamically created content

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
Stacks
Forum Newbie
Posts: 24
Joined: Thu Jun 05, 2008 7:52 pm

Line breaks in dynamically created content

Post 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?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Line breaks in dynamically created content

Post 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply