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

Load html text from database to CKEDITOR for updating purpose

发布于 2015-11-01 18:57:56

I have a html form and I'm using CKEDITOR as a replacement of textarea for formatting purposes. After submitting the form are data from html form inserted into MySQL database. Everything work's great until I tried to retrieve the data from database.

I'm trying to retrieve the data from MySQL to CKEDITOR where I could update them and save them again into to the database.

<?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>

Variable $data equals some value from database. If the variable is equal some number / string, everything works. But the data from database are retrieved as text with HTML tags and the CKEDITOR can't read that probably.

Is it possible to retrieve html text from database and show it in the CKEDITOR as a formatted text without html tags?

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

How does exactly look $data? Maybe you have to use htmlspecialchars_decode.