how to save ckeditor content in mysql database

安稳与你 提交于 2020-03-13 07:00:31

问题


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. title inside title element.

  2. article(text,code-snippet,image) inside "editor1" element.

$_POST['editor'] array looks like:

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


回答1:


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;
} 

Example:

 dataready($_POST['editor']);

So you can use whatever you want PDO or Mysqli.

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

  html_entity_decode($article_text);

Hope this works for you.

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.




回答2:


Yes, you can store the Source Code in your database, that's how Wordpress works.

But remember to escape the strings before sending them to database, using:

mysqli_escape_string();

When you get the post data afterwards, the PHP will just print the HTML on the screen.




回答3:


Simple and easy use base64_encode()

$content = base64_encode($editor_content);

and when you fetch data use base64_decode()

$content = base64_decode($editor_content);


来源:https://stackoverflow.com/questions/34457805/how-to-save-ckeditor-content-in-mysql-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!