if json_decodeit fails (for any reason, including problems with the character set), it will return null, so you can check it, you can use it for special encoding of the encoding mb_detect_encoding.
if(!mb_detect_encoding($response, 'UTF-8', true)){
// error: no utf-8
}else{
$json = json_decode($response,true);
if($json === null){
// error: json_decode failed (or google returned 'null')
}else{
// ok, do great stuff here
}
}
source
share