Created
May 2, 2011 08:57
-
-
Save alnorth/951319 to your computer and use it in GitHub Desktop.
PHP client for the hostip.info API. Taken from http://www.randomsnippets.com/2011/02/03/parsing-xml-data-from-hostip-info-api-service-php/
This file contains hidden or 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 | |
function hostip_get_info($ip) { | |
$content = @file_get_contents('http://api.hostip.info/?ip='.$ip); | |
if ($content != FALSE) { | |
$xml = new SimpleXmlElement($content); | |
$coordinates = $xml->children('gml', TRUE)->featureMember->children('', TRUE)->Hostip->ipLocation->children('gml', TRUE)->pointProperty->Point->coordinates; | |
$longlat = explode(',', $coordinates); | |
$location['longitude'] = $longlat[0]; | |
$location['latitude'] = $longlat[1]; | |
$location['citystate'] = '==>'.$xml->children('gml', TRUE)->featureMember->children('', TRUE)->Hostip->children('gml', TRUE)->name; | |
$location['country'] = '==>'.$xml->children('gml', TRUE)->featureMember->children('', TRUE)->Hostip->countryName; | |
return $location; | |
} | |
else return false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment