Home >Backend Development >PHP Tutorial >求教:查询手机号码归属地,淘宝的接口,返回的数据应该如何处理

求教:查询手机号码归属地,淘宝的接口,返回的数据应该如何处理

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:55:512488browse

http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=15850781443

直接用file_get_contents 返回结果是这样的

__GetZoneResult_ = {    mts:'1585078',    province:'江苏',    catName:'中国移动',    telString:'15850781443',	areaVid:'30511',	ispVid:'3236139',	carrier:'江苏移动'}


应该采用什么方式使用这个接口?

如果直接使用这个file_get_contents  得到的结果应该如何处理 才能得到 归属地?


回复讨论(解决方案)

返回的是一句 js 语句
在 php 中使用的话可以这样解析

$s = file_get_contents('http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=15850781443');preg_match_all("/(\w+):'([^']+)/", $s, $m);$a = array_combine($m[1], $m[2]);print_r($a);
Array
(
    [mts] => 1585078
    [province] => 江苏
    [catName] => 中国移动
    [telString] => 15850781443
    [areaVid] => 30511
    [ispVid] => 3236139
    [carrier] => 江苏移动
)

返回的是一句 js 语句
在 php 中使用的话可以这样解析

$s = file_get_contents('http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=15850781443');preg_match_all("/(\w+):'([^']+)/", $s, $m);$a = array_combine($m[1], $m[2]);print_r($a);
Array
(
    [mts] => 1585078
    [province] => 江苏
    [catName] => 中国移动
    [telString] => 15850781443
    [areaVid] => 30511
    [ispVid] => 3236139
    [carrier] => 江苏移动
)



谢谢xu大
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn