Using nl2br to preserve textarea new lines to mysql… how to return data to textbox nicely?

你离开我真会死。 提交于 2019-12-02 20:04:50

问题


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 nl2br, 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?


回答1:


Store the test in the database with break lines and when you echo it out to the screen run it through nl2br.



来源:https://stackoverflow.com/questions/7666815/using-nl2br-to-preserve-textarea-new-lines-to-mysql-how-to-return-data-to-tex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!