gpt4 book ai didi

php - 在数据库中存储 ckeditor 值(html 标记)的正确方法? (换行问题)

转载 作者:太空宇宙 更新时间:2023-11-03 11:09:53 24 4
gpt4 key购买 nike

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

$content = mysql_real_escape_string($_POST['content']);

当我在插入数据库之前使用 mysql_real_escape_string 时,它会在来自 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

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

Here is a line

rn

name = "Bob"rnlast = "Smith"rnfull = name + " " + last

rn

And another linern

请注意,我确实需要在 pre 标签中保留换行符,所以我不能简单地删除所有换行符。

这是我想看到的:

Here is a line

name = "Bob"

last = "Smith"

full = name + " " + last

And another line

最佳答案

将此行添加到您的代码中:$content = str_ireplace('\r\n', '', $content);

所以你的代码现在应该是:

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

我试过了,它有效。

关于php - 在数据库中存储 ckeditor 值(html 标记)的正确方法? (换行问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9270370/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com