手机号归属地查询
我提供的这个例子是接入的淘宝的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; }
通往牛逼的路上,在意的只有远方!