I am using the below PHP code with Google’s Translate API and I have read that json_encode requires UTF-8 input, so was wondering how do I know if Google is returning UTF-8 encoded characters to me?
// URL Encode string
$str = urlencode($str);
// Make request
$response = file_get_contents('https://www.googleapis.com/language/translate/v2?key=' . GTRAN_KEY . '&target=es&source=en&q=' . $str);
// Decode json response to array
$json = json_decode($response,true);
if
json_decodefails (for any reason, including charset-problems) it will returnnull, so you could check for that. to specifically chck the encoding, you could usemb_detect_encoding.