Try iconv_r($row,"LATIN1","UTF-8//TRANSLIT");
(function below) before you json_encode()
your result.
I have UTF-8 as the table encoding and as the result set encoding, but sometimes folks still manage to submit non-UTF-8 characters via forms and it's troublesome to track down every single input source so I have also wrapped json_encode()
to make it safer. In particular I've had it NULL strings on me containing the degree symbol and "smart quotes" which folks in the UK seem so fond of.
function safe_json_encode($mixed,$missing="TRANSLIT"){
$out=json_encode($mixed);
if ($err= json_last_error()){
iconv_r("UTF-8","UTF-8//$missing",$mixed);
$out=json_encode($mixed);
}
return $out;
}
function iconv_r($charset_i, $charset_o, &$mixed) {
if (is_string($mixed)) {
$mixed = iconv($charset_i, $charset_o, $mixed);
} else {
if (is_object($mixed)){
$mixed = (array) $mixed;
}
if (is_array($mixed)){
foreach ($mixed as $key => &$value) {
iconv_r($charset_i, $charset_o, $value);
}
}
}
}