PHP textarea 将额外的新行保存到 MySQL DB [英] PHP textarea saving extra new lines to MySQL DB
问题描述
在 CodeIgniter 应用程序中,我有一个用于内容输入的文本区域.我想保留新行,但我遇到的问题是,在保存数据时,每个新行都会添加一个额外的新行,然后在我下次编辑时显示在文本区域中.
In a CodeIgniter app, I've a textarea for content entry. I'd like to retain new lines but I'm having the issue that when the data is saved, an extra new line is added with each new line, which then displays in the textarea next time I edit.
我怎样才能摆脱这个额外的新行,最好在保存数据之前?
How can I get rid of this extra new line, preferably before the data is saved?
mysql_real_escape_string 显示数据如下:
mysql_real_escape_string shows the data as follows:
这是第一行\r\n\n
这是第二行\r\n\n
这是第三行
this is the first line\r\n\n
this is the second line\r\n\n
this is the third line
在 textarea 中显示如下:
Which displays in the textarea like so:
this is the first line
this is the second line
this is the third line
我只想要这个:
this is the first line
this is the second line
this is the third line
推荐答案
这是 CI 2.0 的 Reactor 版本中的一个已知错误这让我整个星期都发疯了.我不确定是否有官方补丁,但您可以在此处找到解决方法:
This is a known bug in the Reactor version of CI 2.0 This was driving me nuts all week. I'm not sure if there has been an official patch yet, but you can find a workaround here:
http://codeigniter.com/forums/viewthread/180078/
更多信息:
https://bitbucket.org/ellislab/codeigniter/issue/332/newlines-in-textareas-are-duplicated
这篇关于PHP textarea 将额外的新行保存到 MySQL DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!