在数据库中存储 ckeditor 值(html 标记)的正确方法? (换行问题)
我第一次使用 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 = "Bob"
\r\n
last = "Smith"
\r\n
full = name + " " + last</pre>
\r\n
<p>And another line</p>
\r\n
这是我将其回显到浏览器时看到的内容:
这是一行
rn
姓名=“鲍勃”rnlast=“史密斯”rnfull=姓名+“”+姓氏
rn
还有另一行
请注意,我确实需要维护 pre 标记中的换行符,因此我不能简单地删除所有换行符。
这就是我想看到的:
这是一行
姓名=“鲍勃”
最后=“史密斯”
全名=姓名+“”+姓氏
还有另一行
I'm using ckeditor for the first time and I'm using php to store the value of the ckeditor to a mysql database:
$content = mysql_real_escape_string($_POST['content']);
When I use mysql_real_escape_string before inserting into the DB it adds \r\n all over in the html from ckeditor. This is whats stored in the Database:
<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
This is what I see when I echo it back to the browser:
Here is a line
rn
name = "Bob"rnlast = "Smith"rnfull = name + " " + last
rn
And another line
rn
Note that I do need to maintain the line breaks in the pre tags so I can't simply strip all of the line breaks.
This is what I'd like to see:
Here is a line
name = "Bob"
last = "Smith"
full = name + " " + last
And another line
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将此行添加到您的代码中:
$content = str_ireplace('\r\n', '', $content);
所以您的代码现在应该显示为:
我尝试过,它有效。
Add this line to your code:
$content = str_ireplace('\r\n', '', $content);
So your code should now read:
I tried it and it works.