【发布时间】:2022-01-16 22:33:54
【问题描述】:
我正在将 tinymce 编辑器 的内容保存在 MySQL 表中,并且想将我从数据库中检索到的相同内容粘贴回编辑器中。
我使用 htmlentity() 函数对输入进行编码,将其保存到数据库中,然后在显示之前使用 html_entity_decode() 对内容进行解码。<?php echo html_entity_decode($content->post); ?>
将输出:
<p>adf adf adfadf aadf <img src="images/k0RpgvZ.png" alt="image" width="27" height="18" /></p>
我面临两个问题:
- 如何将此内容显示为 html,而不仅仅是文本?
- 我还想用从数据库中检索到的这个值来设置 tinyEditor 的内容。 这段代码 sn-p 可以做到(取自tiny blog)。
tinymce.init({
selector: '#myTextarea',
setup: function (editor) {
editor.on('init', function (e) {
editor.setContent('<?php echo $content->post; ?>');
});
}
});
但是,它仅适用于 $content->post 包含单个单词(无空格、无换行符、无特殊字符)。
只要有换行符或空格,...,我就会得到错误:
Uncaught SyntaxError: '' string literal contains an unescaped line break
如何处理这些问题?
【问题讨论】:
-
使用 `insted of '。试试这个:editor.setContent(
<?php echo $content->post; ?>);