【问题标题】:CKEditor displaying HTML tags in editorCKEditor 在编辑器中显示 HTML 标签
【发布时间】:2013-03-22 09:53:15
【问题描述】:

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

【问题讨论】:

  • 尝试打开“html 编辑模式”并检查 CKE 输入的内容。这应该会告诉你挖掘的方向
  • set_value 函数是做什么的?
  • 呃!!好问题!那是来自 CodeIgniter 框架,我刚刚删除了它,它工作正常。这个想法之前甚至没有出现,所以我什至把它从上面的代码中省略了!!现在我需要弄清楚如何解决这个 CodeIgniter 问题。非常感谢,当您花太多时间编写代码时,您会变得盲目。
  • 很高兴我能给你一个想法 =) 祝你好运!
  • 最简单的解决方法是这样写$ck_editor-&gt;editor("sec1_content", html_entity_decode(set_value('sec1_content', $default_value)), $config);

标签: php ckeditor


【解决方案1】:

CodeIgniter 的函数set_value() 似乎在某些方面类似于htmlspecialchars()。因此,如果您在 CKEditor 上获得 ,此解决方法可以帮助您。改变

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

【讨论】:

    【解决方案2】:

    对于可能对 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 让我意识到自己的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-21
      • 2016-04-05
      • 2012-07-10
      • 1970-01-01
      • 2017-07-23
      • 2018-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多