I am trying to use one object from the many provided in my json request.
Trying to obtain only the country name from the data that is given.
$location = file_get_contents('http://freegeoip.net/json/'.$_SERVER['REMOTE_ADDR']);
echo $location;
The above code gives me the following string:
{"ip":"x.xx.xx.x","country_code":"FR","country_name":"France","region_code":"A2","region_name":"Bretagne","city":"Brest","zipcode":"","latitude":xxxx,"longitude":xxxx,"metro_code":"","area_code":""}
Any help would be greatly appreciated!
$a = json_decode($location);
echo $a->country_name;
You might also want to have a look on this. http://www.php.net/manual/en/function.json-decode.php
Look for manual json_decode
$tmp = json_decode($location);
echo $tmp->country_code