问题
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:
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.
回答1:
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.
回答2:
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.
回答3:
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).
来源:https://stackoverflow.com/questions/18292609/html-tags-not-being-rendered