Using json response in PHP -


i trying use 1 object many provided in json request.

trying obtain country name data given.

$location = file_get_contents('http://freegeoip.net/json/'.$_server['remote_addr']);  echo $location; 

the above code gives me 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 appreciated!

$a = json_decode($location); echo $a->country_name; 

you might want have on this. http://www.php.net/manual/en/function.json-decode.php


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -