locrizak
locrizak

Reputation: 12279

Best way to convert html entities to html characters

What I need to do is convert any html entities to the actual html character. It can be in javascript or preferable php.

Here's the senario. When I save content to the database from TinyMCE it converts it to html entities for me. That's all good and great when the webpage is rendered, but when I also what to put it in a text input the html entities stick and to a normal user it looks a little wonky.

The only way I can think of doing it is have an array with the entity as the key and character as the value. When an entity is found, check that array and spit out the value.

Does anyone have a better/more efficient solution, possibly using regex?

Upvotes: 0

Views: 1145

Answers (4)

Naveed Ahmad
Naveed Ahmad

Reputation: 3175

You can obviously use html_entity_decode at the PHP level or if you're getting the data to javascript through ajax you can use unescape() javascript function to do the same thing at the client-side

Upvotes: 3

Ryan
Ryan

Reputation: 905

Have you tried applying html_entity_decode to your text? Documentation here

Upvotes: 2

Bil
Bil

Reputation: 543

Use php function html_entity_decode

Upvotes: 2

Quentin
Quentin

Reputation: 944441

html_entity_decode sounds like it is what you are after. It isn't often that people want to take HTML input from users and then display it as text later though.

Upvotes: 3

Related Questions