The code example as stated has a missing '.', causing a syntax error if it is pasted and executed without being checked.
Correct Code:
<?php
$asn = geoip_asnum_by_name('www.example.com');
if ($asn) {
echo 'The ASN is: ' . $asn;
}
?>
(PECL geoip >= 1.1.0)
geoip_asnum_by_name — 获取自治系统号(ASN)
$hostname
): stringgeoip_asnum_by_name() 函数将会返回和 IP 地址相关联的自治系统号(ASN)。
hostname
主机的 IP 地址。
如果成功将会返回自治系统号,如果在数据库中未找到相关信息则返回 false
。
示例 #1 geoip_asnum_by_name() 示例
以下代码将会输出 www.example.com 域名的 ASN。
<?php
$asn = geoip_asnum_by_name('www.example.com');
if ($asn) {
echo 'The ASN is: ' . $asn;
}
?>
以上示例会输出:
The ASN is: AS15133 EdgeCast Networks, Inc
The code example as stated has a missing '.', causing a syntax error if it is pasted and executed without being checked.
Correct Code:
<?php
$asn = geoip_asnum_by_name('www.example.com');
if ($asn) {
echo 'The ASN is: ' . $asn;
}
?>