Last active
July 23, 2017 05:01
-
-
Save iftekharbhuiyan/f672a2fea277f75fc3da3bf317994af8 to your computer and use it in GitHub Desktop.
Reading JSON API Data using PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Desired IP address | |
$ip = '172.217.10.78'; | |
// With Error Reporting: file_get_content(); | |
// Without Error Reporting: @file_get_content(); | |
$content = @file_get_contents('http://freegeoip.net/json/'.$ip); | |
// Result as an Array: json_decode($var, true); | |
// Result as an Object: json_decode($var); | |
$result = json_decode($content, true); | |
// For Array: $result['key']; | |
// For Object: $result->city; | |
echo $result['city']; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment