php 获取到的指定的手机号码,需要判断手机号码的归属地。
/** * 获取手机归属地 * @param $mobile * @return array */ function get_mobile_belongs($mobile){ $type = 'text'; $url = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo"; header("Content-Type:text/html;charset=utf-8"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, "mobileCode={$mobile}&userId="); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); curl_close($ch); $data =simplest_xml_to_array($data); $result = array(); $arr = explode(":",$data['0']); if(!empty($arr[1])){ $arr_second = explode(" ",$arr[1]); } $result['mobile'] = $arr['0']; $result['province'] = $arr_second['0']; $result['city'] = $arr_second['1']; $result['isp'] = $arr_second['2']; return $result; }
代码用例:
$mobile = '131********; $belongs = json_encode(get_mobile_belongs($mobile));
返回结果: