Warm tip: This article is reproduced from serverfault.com, please click

javascript-将html文本从数据库加载到CKEDITOR以进行更新

(javascript - Load html text from database to CKEDITOR for updating purpose)

发布于 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标记的格式化文本?

Questioner
trenccan
Viewed
0
Szymon D 2015-11-02 05:08:17

究竟看起来如何$data也许你必须使用htmlspecialchars_decode