我试图使用外部网站的API获取用户IP信息(国家,城市等)与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;
我可以得到国家,IP和其他东西的代码,但不是城市…
我认为问题在于:
in gml:name
....
这是我试图从中获取数据的XML:
http://api.hostip.info/您需要转义冒号'/<gml':name>(.*)<'/gml':name>/'