如何将ckeditor内容保存在mysql数据库中 [英] how to save ckeditor content in mysql database

查看:547
本文介绍了如何将ckeditor内容保存在mysql数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ckeditor创建一个博客网站.我想结合使用PHP和MySQL将整篇文章保存在数据库中.如果提交包含ckeditor的表单,则会在$_POST['editor']中获得编辑者的内容.我想将文章保存在MySQL数据库中.下图包含整个表单数据.它包括:

I am using ckeditor to create a blog site. I want to use a combination of PHP and MySQL to save the entire article in a database. If I submit the form holding the ckeditor I get the editor's content in $_POST['editor']. I want to save the article in the MySQL database. The following image contains the entire form data. It consists of:

  1. 标题元素中的标题.

"editor1"元素中的文章(文本,代码段,图像).

$_POST['editor']数组如下:

如何将其保存到mysql表中?我可以将整个 editor1 元素保存在 TEXT 类型的列中吗?

How can I save it to a mysql table? Can I save the entire editor1 element in a column of type TEXT?

推荐答案

是的,您可以将整个文章提交到数据库.但是,在您提交之前;尝试使用此功能:

Yes, You can submit your entire article to the database. But, before you submit it; try to use this function:

function dataready($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
} 

示例:

 dataready($_POST['editor']);

因此您可以使用任何您想要的PDO或Mysqli.

So you can use whatever you want PDO or Mysqli.

为避免在打印文章时回显HTML元素,请使用以下功能:

To avoid echoing the HTML elements when you print the article, use this function:

  html_entity_decode($article_text);

希望这对您有用.

PS.对数据库使用列类型TEXT很好.如果要向该列添加更多文本,也可以使用LONGTEXT.

PS. using column type TEXT for your database is fine. You can also use LONGTEXT if you want to add more text to that column.

这篇关于如何将ckeditor内容保存在mysql数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆