如何将用户输入的换行符从TextArea保存到数据库? [英] How to save user-entered line breaks from a TextArea to a database?

查看:112
本文介绍了如何将用户输入的换行符从TextArea保存到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将用户输入的换行从TEXTAREA保存到数据库?每次尝试时,它都会删除换行符。

How do I save user-entered line breaks from a TEXTAREA to a database? Every time I try, it removes the line breaks.

推荐答案

显示内容时,需要将换行符转换为< br /> 标签,否则网页浏览器将不会显示它们。这可能是你认为他们没有被保存的原因。如果您使用的是PHP,请使用 nl2br()函数来执行此操作。在其他语言中,您可以进行字符串替换,用< code>\\\
替换所有出现的<< br />。

When displaying the content you need to convert line breaks into <br /> tags, otherwise the web browser won't display them. This is probably why you think they aren't being saved. If you're using PHP, use the nl2br() function to do this. In other languages you could do a string replace, replacing all occurrences of "\n" with "<br />".

这篇关于如何将用户输入的换行符从TextArea保存到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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