我第一次使用ckeditor,我使用php将ckeditor的值存储到mysql数据库:
$content = mysql_real_escape_string($_POST['content']);当我在插入DB之前使用mysql_real_escape_string时,它从ckeditor将\r\n全部添加到html中。这是存储在数据库中的内容:
<p>Here is a line</p>
\r\n
<pre class=\"code-python\">name = "Bob"
\r\n
last = "Smith"
\r\n
full = name + " " + last</pre>
\r\n
<p>And another line</p>
\r\n当我将它回显到浏览器时,我看到了这样的情况:
这里有一行
rn
name = "Bob"rnlast = "Smith"rnfull = name +“”+ last
rn
另一行rn
注意,我do需要维护预标记中的换行符,这样我就不能简单地删除所有的换行符。
这就是我想看到的:
这里有一行
名称= "Bob“
最后=“史密斯”
全称+“”+最后
和另一条线
发布于 2012-10-18 07:38:20
将这一行添加到代码中:$content = str_ireplace('\r\n', '', $content);
因此,您的代码现在应该是:
$content = mysql_real_escape_string($_POST['content']);
$content = str_ireplace('\r\n', '', $content);我试过了而且成功了。
https://stackoverflow.com/questions/9270370
复制相似问题