<?php
function inquiry_number_infor($phonenumber)
/*
*传入手机号码,通过API的到xml格式数据,对xml进一步解析,最后返回相应的号码信息的数组。
*
*@param string $phonenumber
*
*@return array
*/
{
$url = "http://api.showji.com/Locating/default.aspx?m=$phonenumber&output=xml&callback=querycallback";
$lines_array = file($url);
$lines_string = implode('', $lines_array);
echo htmlspecialchars($lines_string);
echo "</br>";
$p = xml_parser_create();
xml_parse_into_struct($p, $lines_string, $vals, $index);
xml_parser_free($p);
$return_arr = array();
foreach($vals as $val)
{
$key = $val["tag"];
if($key != "QUERYRESPONSE")
{
$value = $val["value"];
$return_arr[$key] =$value;
}
if($key === "QUERYRESULT" && $value === "False") break;
}
return $return_arr;
}
$ret = inquiry_number_infor("11210982674");
//$ret = inquiry_number_infor("15210982674");
print_r($ret);
转载于:https://www.cnblogs.com/vania/p/4516773.html