我有一个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标记的格式化文本?
究竟看起来如何$data
?也许你必须使用htmlspecialchars_decode。
当我在textarea中使用htmlspecialchars_decode时,它可以工作。谢谢。