//通過搜狐接口獲取用戶的ip; $json = file_get_contents('http://pv.sohu.com/cityjson?ie=utf-8'); preg_match_all('/"cip"\s*:\s*"([^"]+)"/', $json, $result, PREG_SET_ORDER); if (empty($result)) { $this->error("未獲取到用戶ip!"); } $ip = $result[0][1]; //調用淘寶接口獲取城市; $res = file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=$ip"); $res = json_decode($res, true); //獲取瀏覽用戶所在城市; $m = $res['data']['city'].'市';