Search code examples
phpwordpresshtml-encode

html_entity_decode does not decode


I have a problem with decoding html entities for browser display. I'm trying to display the blog description from a wordpress blog. The text is being html entity encoded before it is saved in the db. So in order to display, for instance, a hyper link the text has to be html entity decoded back, so the a-tag is being rendered properly.

But when I try to decode the text it still comes out as html entities.

The output before being decoded:

echo(bloginfo( 'description' )); //output: Display a hyper link. <a href="">READ MORE</a>

The output when being decoded. And here's my problem. It is still not decoded! Check the output.

echo(html_entity_decode(bloginfo( 'description' ))); //output: Display a hyper link. <a href="">READ MORE</a>

And when I try to hard code the text to be decoded, it works!

echo(html_entity_decode('Display a hyper link. &lt;a href=""&gt;READ MORE&lt;/a&gt;')); //output: Display a hyper link. <a href="">READ MORE</a>

I've looked at the php manual, and tried different charsets and quote styles as arguments. But still no luck.

What am I doing wrong, any ideas?


Solution

  • The bloginfo function does not return the text, it echoes it directly. Your "echo" will therefore in fact echo nothing!

    Use get_bloginfo instead.