PHP html entity decode UTF-8 encoding

For a multilanguage site, using html_entity_decode without encoding type is risky to your website as in some cases, the translated language show weird characters.
In version of php prior to 5.4.0, if encoding omitted, default encoding value is ISO-8859-1, and UTF-8 auto set only from PHP 5.4.0

html_entity_decode($string, ENT_COMPAT, 'UTF-8')

Constant Name Description
ENT_COMPAT Will convert double-quotes and leave single-quotes alone.
ENT_QUOTES Will convert both double and single quotes.
ENT_NOQUOTES Will leave both double and single quotes unconverted.
ENT_HTML401 Handle code as HTML 4.01.
ENT_XML1 Handle code as XML 1.
ENT_XHTML Handle code as XHTML.
ENT_HTML5 Handle code as HTML 5.

By Keenlio, April 7, 2014

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

seven × 7 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>