I'm building a simple blog system with FuelPHP and TinyMCE editor.

When I format my text in the TinyMCE (or CKEditor, doesn't matter) and save it in my database everything is OK. However when I print the text back, surprisingly, my browser won't render the html tags and displays them as plain text!

I have checked and I don't have any kind of CDATA in the page, that might cause the issue.

Here is how it renders:

How it renders

However, when inspecting the issue with FireBug, I noticed a lot of spaces before the <h2> tag is being printed! If I just make a small change in the spaces (Remove one or add another), then the browser will render the tags and display the text properly!!

Can you guys help me with this issue? It's really weird.

有帮助吗?

解决方案

when you save your data in database its encoded for some security reasons you just need to

html_entity_decode("string retrived from database");

and then print it.

其他提示

Instead of encoding and decoding you can use the set_safe() method or use the $filter argument in set().

Like this:

$view->set_safe('body', $data);

Or

$view->set('body', $data, false);

Or whitelist your view. Which will prevent decoding.

How can you pass the data to the view? Can you show the code?

If you are using the View class there is a method which can let you choice when to encode the text or not (default is yes).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top