• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
车车大人
博客园    首页    新随笔    联系   管理     

手机号归属地查询

我提供的这个例子是接入的淘宝的api,通过file_get_content进行信息的采集

    //这个是调用
    public function teltest(){
        $mobile = "13701328266";  //要查询的电话号码(项目中用的时候把这个替换成变量就可以了)
        $content = $this->get_mobile_area($mobile);
        print_r($content);
    }


    //查询手机号归属地
    function get_mobile_area($mobile){
        //根据淘宝的数据库调用返回值
        $url = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=".$mobile."&t=".time();

        $content = file_get_contents($url);
        $contents = iconv("gb2312", "UTF-8",$content);
        return $this->formatData($contents);
    }

    //通过设置规则把获取到的不规则信息转为正常数组
    public static function formatData($data = null) {
        $ret = null;

        if (!is_null($data)) {
            $ret = preg_match_all("/(\w+):'([^']+)/", $data, $res);
            $ret = array_combine($res[1], $res[2]);
        }

            return $ret;
    }

 

通往牛逼的路上,在意的只有远方!
posted @ 2017-04-07 14:38  车车大人  阅读(467)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3