【发布时间】:2015-11-01 18:57:56
【问题描述】:
我有一个 html 表单,我使用 CKEDITOR 代替 textarea 来进行格式化。提交表单后,将 html 表单中的数据插入 MySQL 数据库。在我尝试从数据库中检索数据之前,一切正常。
我正在尝试将数据从 MySQL 检索到 CKEDITOR,在那里我可以更新它们并将它们再次保存到数据库中。
<?php
if(isset($_GET['id'])){
$id=$_GET['id'];
$sql = "SELECT * FROM article WHERE id='$id'";
$result = $conn->query($sql);
// output data of each row
while($row = $result->fetch_assoc()) {
$data=$row['topic'];
}
}
?>
<textarea type="text" name="topic" id="topic" rows="10" cols="80"> </textarea>
<script>
// Replace the <textarea id="topic"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace( 'topic' );
CKEDITOR.instances.topic.setData( '<p><?php echo $data;?></p>', function()
{
this.checkDirty(); // true
});
</script>
变量$data 等于数据库中的某个值。如果变量等于某个数字/字符串,则一切正常。但是数据库中的数据被检索为带有 HTML 标记的文本,CKEDITOR 可能无法读取。
是否可以从数据库中检索 html 文本并在 CKEDITOR 中显示为没有 html 标签的格式化文本?
【问题讨论】:
标签: javascript php html mysql ckeditor