case 2: //国家信息被重定向
fseek($this->fh, $this->getLong3());
$location['country'] = $this->getInfo();
fseek($this->fh, $offset + 8);
$location['area'] = $this->getArea();
break;
default: //国家信息没有被重定向
$location['country'] = $this->getInfo($byte);
$location['area'] = $this->getArea();
break;
}
//gb2312 to utf-8(去除无信息时显示的CZ88.NET)
foreach ($location as $k => $v) {
$location[$k] = str_replace('CZ88.NET','',iconv('gb2312', 'utf-8', $v));
}
return $location;
}
//析构函数
function __destruct() {
fclose($this->fh);
}
}
$ip = new ip();
$addr = $ip -> ip2addr('IP地址');
print_r($addr);
?>