Php 在数据库中存储ckeditor值(html标记)的正确方法?(线路中断故障)

Php 在数据库中存储ckeditor值(html标记)的正确方法?(线路中断故障),php,mysql,ckeditor,newline,Php,Mysql,Ckeditor,Newline,我第一次使用ckeditor,我使用php将ckeditor的值存储到mysql数据库: $content = mysql_real_escape_string($_POST['content']); 当我在插入数据库之前使用mysql\u real\u escape\u字符串时,它会在ckeditor的html中添加\r\n所有内容。这是存储在数据库中的内容: <p>Here is a line</p> \r\n <pre class=\"code-p

我第一次使用ckeditor,我使用php将ckeditor的值存储到mysql数据库:

$content = mysql_real_escape_string($_POST['content']);
当我在插入数据库之前使用mysql\u real\u escape\u字符串时,它会在ckeditor的html中添加\r\n所有内容。这是存储在数据库中的内容:

<p>Here is a line</p>
\r\n
<pre class=\"code-python\">name = &quot;Bob&quot;
\r\n
last = &quot;Smith&quot;
\r\n
full = name + &quot; &quot; + last</pre>
\r\n
<p>And another line</p>
\r\n
这里有一行

\r\n name=“鲍勃” \r\n last=“史密斯” \r\n 完整=名称+“”+最后一个 \r\n 还有另一条线

\r\n
这是我将其回显到浏览器时看到的内容:

这是一条线

注册护士

name=“Bob”rnlast=“Smith”rnfull=name+”“+last

注册护士

还有另一条线 注册护士

请注意,我需要在pre标记中保留换行符,这样我就不能简单地去掉所有换行符

这就是我想看到的:

这是一条线

name=“鲍勃”

last=“史密斯”

完整=名称+“”+最后一个

还有另一条线


将此行添加到代码中:
$content=str\u ireplace('\r\n','$content)

因此,您的代码现在应该是:

$content = mysql_real_escape_string($_POST['content']);
$content = str_ireplace('\r\n', '', $content);

我试过了,效果很好。

将这一行添加到代码中:
$content=str\u ireplace('\r\n','$content)

因此,您的代码现在应该是:

$content = mysql_real_escape_string($_POST['content']);
$content = str_ireplace('\r\n', '', $content);

我试过了,效果很好。

我应该注意,通过不使用mysql\u real\u escape\u字符串,我得到了我想要和期望的东西,但我不想在没有它的情况下插入数据库。我应该注意,不使用mysql\u real\u escape\u字符串,我得到了我想要和期望的东西,但是我不想在没有它的情况下插入数据库代替。使用
str\u-ireplace(“\r\n”,“”,$content)取而代之。