I want only the unencoded characters to get converted to html entities, without affecting the entities which are already present. I have a string that has previously encoded entities, e.g.:
gaIUSHIUGhj>‐ hjb×jkn.jhuh>hh> …
When I use htmlentities(), the & at the beginning of entities gets encoded again. This means ‐ and other entities have their & encoded to &:
×
I tried decoding the complete string, then encoding it again, but it does not seem to work properly. This is the code I tried:
header('Content-Type: text/html; charset=iso-8859-1');
...
$b = 'gaIUSHIUGhj>‐ hjb×jkn.jhuh>hh> …';
$b = html_entity_decode($b, ENT_QUOTES, 'UTF-8');
$b = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $b);
$b = htmlentities($b, ENT_QUOTES, 'UTF-8');
But it does not seem to work the right way. Is there a way to prevent or stop this from happening?