I am saving the content of the tinymce editor in MySQL table, and would like to paste the same content that I have retrieved from the database back in the editor.
I use the htmlentities() function to encode the input, save it into the database and then decode the content with html_entity_decode() before displaying it.
<?php echo html_entity_decode($content->post); ?>
will output:
<p>adf adf adfadf aadf <img src="images/k0RpgvZ.png" alt="image" width="27" height="18" /></p>
I am facing two issues:
- How to display this content as html, not just as text ?
- I would also like to set the content of the tinyEditor with this value retrieved from the database. This code snippet does it (taken from tiny blog).
tinymce.init({
selector: '#myTextarea',
setup: function (editor) {
editor.on('init', function (e) {
editor.setContent('<?php echo $content->post; ?>');
});
}
});
However, it only works when $content->post
contents a single word (no space, no line break, no special character).
As soon as there is a line break, or a space,..., I get the error:
Uncaught SyntaxError: '' string literal contains an unescaped line break
How to handle those issues ?
CodePudding user response:
Try this:
editor.setContent(`<?php echo $content->post; ?>`);