I am displaying data from an sql database in a textarea which will be altered by the user then re-submitted to the database.
The problem is displaying a line break. I get <br /> displayed in the textarea rather than the newline.
Can anyone help?

Recommended Answers

All 3 Replies

That means that the data entered into the database had a <br /> in it (and <br /> is the code for a line break). It is VERY likely that your input script is first converting the newline into a <br /> then inserting it into the databsae.

What I do is input the content unaltered, but when it comes to displaying it on a web page, via php, I run the only bits that will have newlines through the php function nl2br() - see the manual. nl2br() produces a <br />, so what I actually did just recently was write my own function to make it insert <br> instead, just to keep the validation tool happy and to exercise my brain. (Because I don't use xhtml, as it is a dead-end and most browsers can't read it, so they convert it to html first!) I don't run it through the function when it is displayed in a textarea for editing, however. So no <br />, just the newline.

Use str_replace() to replace <br> with \n (newline) before displaying in text area.

Thanks for the replies. All working nicely now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.