echo 'iso-8859-1 encode <br />';
$var=htmlentities('< > & \' "', ENT_QUOTES, 'iso-8859-1');
echo 'iso decode: <br />';
echo html_entity_decode($var, ENT_QUOTES, 'iso-8859-1');
echo '<br />';
echo 'utf decode: <br />';
echo html_entity_decode($var, ENT_QUOTES, 'utf-8');
So if I use iso-8859-1 htmlentities('< > & \' "', ENT_QUOTES, 'iso-8859-1'), I can still use utf8 html_entity_decode($var, ENT_QUOTES, 'utf-8') to covert them back.
But if I use utf-8 htmlentities, then when I use iso-8859-1 htmle_entity_decode, some of the unicode htmlentities will not be coverted back.
I am working with 3rd party database, I need to html_entity_decode the values. Due to I don't know if the original htmlentities character set is iso-8859-1 or utf-8, I am using html_entity_decode($var, ENT_QUOTES, 'utf-8'), am I missing something here?
Thanks!