I have foreign language strings stored in utf8. When displaying them, I want them to be transform in such a way that accented chars become their html counterparts, e.g. é
becomes é
However I phrase my search, all I can find is htmlentities()
which does not do it.
Advertisement
Answer
Make sure you’re properly specifying the encoding when you call htmlentities()
.
The documentation shows that it defaults to 'UTF-8'
, but if you read down a bit further, you’ll see that that’s new as of PHP 5.4. If you’re using an older version, the default is actually 'ISO-8859-1'
, and you’ll need to make sure you explicitly specify it as 'UTF-8'
instead of relying on the default behaviour.
htmlentities($string, 0, 'UTF-8');