php利用腾讯ip分享计划获取地理位置示例分享_PHP

WBOY
Release: 2016-06-01 11:56:40
Original
982 people have browsed it

复制代码 代码如下:
function getIPLoc_QQ($queryIP){   
$url = 'http://ip.qq.com/cgi-bin/searchip?searchip1='.$queryIP;   
$ch = curl_init($url);   
curl_setopt($ch,CURLOPT_ENCODING ,'gb2312'); 
curl_setopt($ch, CURLOPT_TIMEOUT, 10);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回 
$result = curl_exec($ch);   
$result = mb_convert_encoding($result, "utf-8", "gb2312"); // 编码转换,否则乱码
curl_close($ch);  
preg_match("@(.*)

@iU",$result,$ipArray);   
$loc = $ipArray[1];   
return $loc;
 }
//使用
echo getIPLoc_QQ("183.37.209.57"); //即可得到IP地址所在的地址位置。  
?>
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template