Using nl2br to preserve textarea new lines to mysql... how to return data to textbox nicely?
I have a form with a textarea whose results are inserted into a mysql database. I'm using nl2br to preserve the line breaks.
However, because this inserts br's in the text, when a user goes to edit what they've entered in the textarea, it shows all the br's in the textarea which were saved in mysql (looks ugly for people who don't know html).
So, if I don't use nl2开发者_如何学Cbr, the line breaks look nice when echoed back in the textarea but not saved in the database correctly. If I use nl2br, the line breaks are saved in the database correctly but look ugly when echoed back. How do I echo the saved textarea contents back onto the page without showing the br's all over the place?
Store the test in the database with break lines and when you echo it out to the screen run it through nl2br
.
精彩评论