Pink Code
Pink Code

Reputation: 1834

PHP function for converts html entities back to html special characters

I have this function for converts html entities back to html special characters:

function html_entity_decode_utf8($value, $double_encode = TRUE) 

{
    return htmlspecialchars( (string) $value, ENT_QUOTES, "UTF-8", $double_encode);


}

Now, I need to Print this:

echo html_entity_decode_utf8('&zwnj');

Output is:

&zwnj

Why htmlspecialchars notwork ?! how i can fix this?

Upvotes: 0

Views: 182

Answers (1)

larsAnders
larsAnders

Reputation: 3813

htmlspecialchars converts & into &. To convert back, you need htmlspecialchars_decode:

function html_entity_decode_utf8($value) 
{
    return htmlspecialchars_decode( (string) $value, ENT_QUOTES);
}

To see more options for using this function, check out the documentation.

Upvotes: 2

Related Questions