php 在编辑器中显示HTML标记的CKEditor

ig9co6j1  于 2023-01-29  发布在  PHP
关注(0)|答案(3)|浏览(136)

我正在使用CKEditor并将内容保存到MySQL数据库。当尝试在编辑器中再次编辑内容时,HTML标记显示为文本,例如:

my test<br />and second line

我怎样才能让它再次正确地显示在编辑器中?
我已经摆弄htmlentities和html_entity_decode以及CKEditor相关设置一个多小时了,都无济于事。

$config = array();
   $config['enterMode'] = 2;
   $config['shiftEnterMode'] = 1;
   //$config['basicEntities'] = FALSE;
   //$config['entities'] = FALSE;
   //$config['entities_greek'] = FALSE;
   //$config['entities_latin'] = FALSE;
   //$config['htmlDecodeOutput'] = TRUE;

   $ck_editor->editor("sec1_content", $default_value, $config);
xdnvmnnf

xdnvmnnf1#

看起来CodeIgniter的func set_value()在某些方面与htmlspecialchars()类似。因此,如果您正在使用CKEditor,此变通方案可以帮助您。Change<any_tag> on CKEditor this workaround can help you. Change

$ck_editor->editor("sec1_content", set_value('sec1_content', html_entity_decode($default_value)), $config);

对此:

$ck_editor->editor("sec1_content", html_entity_decode(set_value('sec1_content', $default_value)), $config);
  • 波兰共和国 *

把html_entity_decode放在set_value的周围,原因很明显是set_value方法可能不使用$default_value参数,而是返回发布的数据。

pcww981p

pcww981p2#

对于使用CodeIgniter/CKEditor时可能遇到相同问题的用户:
解决此问题并仍使用CodeIgniter set_value()方法的方法如下:

$ck_editor->editor("sec1_content", set_value('sec1_content', html_entity_decode($default_value)), $config);

请执行以下操作:

$ck_editor->editor("sec1_content", html_entity_decode(set_value('sec1_content', $default_value)), $config);

把html_entity_decode放在set_value的周围,原因很明显是set_value方法可能不使用$default_value参数,而是返回发布的数据。
谢谢你coramba让我意识到我的错误。

nbnkbykc

nbnkbykc3#

在Laravel中遇到此问题的任何人,strip_tags函数都很有帮助。{{ strip_tags($your_content) }}

相关问题