使用nl2br保留textarea换行到mysql的新行...如何很好地将数据返回到textbox? [英] Using nl2br to preserve textarea new lines to mysql... how to return data to textbox nicely?

查看:99
本文介绍了使用nl2br保留textarea换行到mysql的新行...如何很好地将数据返回到textbox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有textarea的表单,其结果被插入到mysql数据库中.我正在使用nl2br保留换行符.

I have a form with a textarea whose results are inserted into a mysql database. I'm using nl2br to preserve the line breaks.

但是,因为这会在文本中插入br,所以当用户去编辑他们在textarea中输入的内容时,它会显示出textarea中保存在mysql中的所有br(对于那些不这样做的人来说看起来很丑陋)知道html).

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).

因此,如果我不使用nl2br,则在textarea中回显但未正确保存在数据库中时,换行符看起来不错.如果使用nl2br,则换行符会正确保存在数据库中,但回显时却很难看.如何在不显示br整个位置的情况下,将保存的textarea内容回显到页面上?

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?

推荐答案

使用断行将测试存储在数据库中,当您将其回显到屏幕时,通过nl2br运行它.

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

这篇关于使用nl2br保留textarea换行到mysql的新行...如何很好地将数据返回到textbox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆