2

I am using a CKEditor and saving content to a MySQL database. When trying to edit the content again in the editor, I am getting HTML tags displayed as text, for example:

my test<br />and second line

How can I have it display in the editor correctly again?

I have been fiddling with htmlentities and html_entity_decode and CKEditor related settings for over an hour now, with no avail.

   $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);
11
  • try to switch on 'html edit mode' and check what CKE having on input. that should show you direction to dig Commented Mar 22, 2013 at 10:10
  • 1
    what does set_value function doing? Commented Mar 22, 2013 at 10:33
  • 1
    Duh!! Good question! That is from the CodeIgniter framework, I just removed it and it work fine. The thought didn't even occur before so I even left it out from the above code!! Now I need to figure out how to fix this CodeIgniter issue. Thanks a lot man, when you spend too much time coding something you become blind. Commented Mar 22, 2013 at 10:37
  • 1
    Glad i could give you an idea =) good luck! Commented Mar 22, 2013 at 10:40
  • 1
    easiest workaround is to write it like this $ck_editor->editor("sec1_content", html_entity_decode(set_value('sec1_content', $default_value)), $config); Commented Mar 22, 2013 at 10:41

3 Answers 3

7

It seems that CodeIgniter's func set_value() acts like htmlspecialchars() in some way. So if you are getting <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);

To this:

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

PoloRM
Put html_entity_decode around set_value. The reason for this is obviously because the set_value method might not use the $default_value parameter but return the posted data instead.

Sign up to request clarification or add additional context in comments.

Comments

1

For people who might have the same issue with CodeIgniter/CKEditor:

The way to resolve this issue and still use the CodeIgniter set_value() method is the following:

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

Do this:

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

Put html_entity_decode around set_value. The reason for this is obviously because the set_value method might not use the $default_value parameter but return the posted data instead.

Thank you coramba for making me realize my mistake.

Comments

0

Anyone having this issue in Laravel the strip_tags function is helpful. In the view : {{ strip_tags($your_content) }}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.