Reputation: 687
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:
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 ?
Upvotes: 0
Views: 235
Reputation: 626
Try this:
editor.setContent(`<?php echo $content->post; ?>`);
Upvotes: 3