php根据手机号码获取省份
生活随笔
收集整理的這篇文章主要介紹了
php根据手机号码获取省份
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
接口:https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=13526527733
public function getProviceBymobile($mobile){$url = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm";$curl = new Curl();// $curl->setHeaders("Content-type:text/html;charset=UTF-8");$curl->get($url, ['tel' => $mobile]);$str1 = $this->str_to_utf8($curl->response);$str1 = preg_replace('# #', '', $str1);$start = strpos($str1,"=")+1;// $str1 = "\"".substr($str1,$start)."\"";$str1 = substr($str1,$start);// echo $str1;die();$str1 = "{ mts:'15136469515', province:'河南', catName:'中國聯通', telString:'15136469515', areaVid:'30500', ispVid:'137815084', carrier:'河南聯通' } ";$str1 = str_replace("'","\"", $str1); // echo $str1;die();$re = $this->ext_json_decode($str1,true);$province = $re['province'];return $province;}public function str_to_utf8 ($str = ''){$encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));// var_dump($encode);die();if($encode == 'UTF-8'){return $str;}else{return mb_convert_encoding($str, 'UTF-8', $encode);}}public function ext_json_decode($str, $mode=true){if(preg_match('/\w:/', $str)){$str = preg_replace('/(\w+):/is', '"$1":', $str);}return json_decode($str, $mode);}/*** * 把對象轉成數組* @param $object 要轉的對象$object */public function objectToArray($object){ $object = json_decode( json_encode( $object),true);return $object;}結果:
_GetZoneResult = {
mts:‘1352652’,
province:‘河南’,
catName:‘中國移動’,
telString:‘13526527733’, areaVid:‘30500’, ispVid:‘3236139’, carrier:‘河南移動’ }
總結
以上是生活随笔為你收集整理的php根据手机号码获取省份的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux tar打包大文件并分割传输另
- 下一篇: php把字符串转为utf-8