2

我正在使用 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);
4

2 回答 2

7

似乎 CodeIgniter 的 func在某种程度上set_value()表现得像。htmlspecialchars()因此,如果您在 CKEditor 上获得 <any_tag>,此解决方法可以帮助您。改变

$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);

PoloRM
将 html_entity_decode 放在 set_value 周围。这样做的原因显然是因为 set_value 方法可能不使用 $default_value 参数,而是返回发布的数据。

于 2013-03-22T11:00:51.640 回答
1

对于可能对 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 参数,而是返回发布的数据。

谢谢你让我意识到我的错误。

于 2013-03-22T10:46:01.603 回答