1.安装pear
yum install php-pear
2.pear安装完后可以安装qqwry了
#pecl install qqwry-beta
3.修改/etc/php.ini配置文件,将该模块写入, 将如下内容写入php.ini最后即可。
[qqwry]
extension=qqwry.so
4.重启服务生效。
apache
service httpd restart
nginx
service php-fpm restart
5.使用demo
$qqwry=new qqwry('/yourpath/QQWry.Dat');
list($addr1,$addr2)=$qqwry->q('127.0.0.1');
$addr1=iconv('GB2312','UTF-8',$addr1);
$addr2=iconv('GB2312','UTF-8',$addr2);
echo $addr1,'|',$addr2,"\n";
$arr=$qqwry->q('4.4.2.2');
$arr[0]=iconv('GB2312','UTF-8',$arr[0]);
$arr[1]=iconv('GB2312','UTF-8',$arr[1]);
echo $arr[0],'|',$arr[1],"\n";
$arr=$qqwry->q('8.8.8.8');
$arr[0]=iconv('GB2312','UTF-8',$arr[0]);
$arr[1]=iconv('GB2312','UTF-8',$arr[1]);
echo $arr[0],'|',$arr[1],"\n";
输出:
本机地址|
IANA保留地址|
美国|加利福尼亚州山景市谷歌公司DNS服务器