Rumah > Artikel > pembangunan bahagian belakang > php如何获取ip的地理位置呢
php怎么获取ip的地理位置呢
我调用QQ的接口
<br />function getIPLoc_QQ($queryIP){ <br /> $url = 'http://ip.qq.com/cgi-bin/searchip?searchip1='.$queryIP; <br /> $ch = curl_init($url); <br /> curl_setopt($ch,CURLOPT_ENCODING ,'gb2312'); <br /> curl_setopt($ch, CURLOPT_TIMEOUT, 10); <br /> curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回 <br /> $result = curl_exec($ch); <br /> $result = mb_convert_encoding($result, "utf-8", "gb2312"); // 编码转换,否则乱码 <br /> curl_close($ch); <br /> preg_match("@<span>(.*)</span></p>@iU",$result,$ipArray); <br /> $loc = $ipArray[1]; <br /> return $loc; <br />} <br />