python - 关于textarea插入换行符的问题
PHP中文网
PHP中文网 2017-04-17 17:37:17
0
4
395

flask-wtf
Textareafield
编辑一段文字 插入数据库 再从数据库查询出来 换行符就不见了 如何将换行符一起插入数据库?
例如:
我们
你们
他们
查询出来结果就变成了:
我们 你们 他们

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(4)
左手右手慢动作

Dynamic join <p> or

Ty80

This should be a database storage problem. Check the data type of the fields where you store these contents. Also refer to this article http://www.webtag123.com/sql/23888.html

伊谢尔伦

When outputting, include <pre>
or replace the line break in the query content with

Peter_Zhu

If you mean putting it in the HTML structure without line breaks, then possible problems and solutions:

  1. Because HTML is br newline and does not support the escape character n. The carriage return and line feed in the textarea are not visible, and the line feed is done through n.
    console.log('your query data') Check whether there is a line break in the console. Or yourCon.indexOf("n") to see if there is n. If so, yourCon.replace("n","<br/>") completes the replacement and then checks whether it is a newline. Of course, line breaks may also be r, nrbr换行,不支持转义字符n。textarea里回车换行时不可见的,是通过n换行的。
    console.log('你的查询数据') 看是否在控制台有换行。或者 yourCon.indexOf("n")查看是否有n。若有的话, yourCon.replace("n","<br/>")完成替换, 再检查是否换行。当然换行也可能是rnr

  2. 如果第一种不能解决。或者完全没有换行符的出现。那就就把数据replace("n","<br/>") ,提前把n换成br

If the first method cannot be solved. Or no line breaks appear at all. Then just replace("n","<br/>") and replace n with br in advance. Or just replace it with other characters before storing it in the database, and then convert it back when getting it.

🎜 🎜Click here to see my blog. I wrote a simple summary when I encountered this problem last time🎜
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template