【发布时间】:2011-03-08 18:01:28
【问题描述】:
我将如何使用 Regex 获取关于 IP 到 Location API 的信息
这是 API
http://ipinfodb.com/ip_query.php?ip=74.125.45.100
我需要获取国家名称、地区/州和城市。
我试过了:
$ip = $_SERVER["REMOTE_ADDR"];
$contents = @file_get_contents('http://ipinfodb.com/ip_query.php?ip=' . $ip . '');
$pattern = "/<CountryName>(.*)<CountryName>/";
preg_match($pattern, $contents, $regex);
$regex = !empty($regex[1]) ? $regex[1] : "FAIL";
echo $regex;
当我执行 echo $regex 时,我总是失败,我该如何解决这个问题
【问题讨论】: