I’m trying to use an external site’s API to get users IP info (country, city, etc etc) with file_get_contents:
$ht="http://api.hostip.info/?ip=99.99.99.99";//example ip address<<
$com = file_get_contents("$ht");
preg_match('/<countryName>(.*)<\/countryName>/',$com,$oun);
preg_match('/<gml:name>(.*)<\/gml:name>/',$com,$it);
$country=$oun[1];
$city=$it[1];
echo $country, $city;
I can get the country, IP and other things with that code, just not the city…
I think the issue lies with the
:
in gml:name….
Here is the XML I’m trying to get the data from:
You need to escape the colon
'/<gml\:name>(.*)<\/gml\:name>/'