In my PHP webservice I have to return some arrays containing strings with accented letters in JSON format (I parse them in my client app with JS).
But the htmlentities
function replaces the strings containing accented letters with empty strings! If I don't use htmlentities
, I get an error on json_encode
.
$a = array('key' => 'èàìòù');
foreach ($a as $k => $v)
$a[$k] = htmlentities($v, ENT_QUOTES | ENT_HTML5, 'UTF-8');
json_encode($a);
I also tried the ENT_COMPAT
option, but I get only empty values.
Note that if I print my array with print_r
before htmlentities
, the content is ok.
More information:
Every file is in UTF-8 w/o BOM format (saved with Notepad++). I already tried to add the headers to set UTF-8 in my PHP and HTML. The DB table is in utf8_unicode_ci format.
Versions: PHP 5.3.3, MySQL 5.5.30-1.
Thank you for your help!