I’m trying to do a curl request to the google currency converter URL. This part works, and I get back the JSON data however the data appears to be in the wrong encoding. If I try to convert encoding or adjust the values in any way it doesn’t work and my json_decode returns NULL.
Do I need to specify encoding or is it related to the keys not having quotes around them?
Here’s some code to get a result from them:
$url = "https://www.google.com/ig/calculator?hl=en&q=" . $amount . $from . "=?" . $to;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$return = curl_exec($ch);
curl_close($ch);
var_dump($return);
The result is usually something around this {lhs: "9Â 808.90 U.S. dollars",rhs: "7Â 986.40287 Euros",error: "",icc: true}
I converted the encoding to ISO-8859-1 and it had proper spaces, but it still won’t json_decode properly…
Any suggestions?
I never get that weird strings.
test.php
things you should try:
,and it’s another character there