geoip_region_by_name
(PECL geoip >= 0.2.0)
geoip_region_by_name — 获取国家和地区代码
说明
geoip_region_by_name(string
$hostname
): arraygeoip_region_by_name() 函数将会返回与主机或者 IP 地址相关的国家和地区代码。
该函数只对购买了商业 GeoIP Region 版本的用户可用。否则将会抛出一个警告!
所返回的关联数组的各字段具体含义如下:
- "country_code" -- 由两个字母组成的国家代码(参见 geoip_country_code_by_name())
- "region" -- 地区代码。 (比如: CA 对应 California)
参数
-
hostname
-
查找的主机或者 IP 地址。
返回值
成功,返回关联数组, 如果信息未找到则返回 false
。
范例
示例 #1 geoip_region_by_name() 例子:
以下例程将会打印对应 example.com 主机的包含国家和地区代码的关联数组。
<?php
$region = geoip_region_by_name('www.example.com');
if ($region) {
print_r($region);
}
?>
以上例程会输出:
Array ( [country_code] => US [region] => CA )

User Contributed Notes 1 note
blacksdeva at gmail dot com ¶
8 years ago
Hi Kaushal,
You have to install geoip first before using its features, this link might help http://php.net/manual/en/geoip.setup.php if you get stuck just tell me what distro you are using
备份地址:http://www.lvesu.com/blog/php/function.geoip-region-by-name.php