PHP根据手机号获取归属地

 $doc = new DOMDocument();
 $filepath="http://life.tenpay.com/cgi-bin/mobile/MobileQueryAttribution.cgi?chgmobile=15238275006";//返回数据为xml格式的
 $doc->load($filepath);
//解析xml数据,得到需要的数据,这里我只需要得到省市,即可
 $books = $doc->getElementsByTagName("root");
 foreach($books as $book)		
 {	
<span style="white-space:pre">	</span>$provinces = $book->getElementsByTagName("province");
	$province = $provinces->item(0)->nodeValue;
	$citys = $book->getElementsByTagName("city");
	$city = $citys->item(0)->nodeValue;
	$usercity=trim($province).",".trim($city);
 }



下面为返回数据格式

  <?xml version="1.0" encoding="gb2312" ?> 
- <root>
  <ENV_CgiName>/cgi-bin/mobile/MobileQueryAttribution.cgi</ENV_CgiName> 
  <ENV_ClientAgent>Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; .NET CLR 1.1.4322; InfoPath.2; Tablet PC 2.0)</ENV_ClientAgent> 
  <ENV_ClientIp>117.85.147.186</ENV_ClientIp> 
  <ENV_QueryString>chgmobile=15238275006</ENV_QueryString> 
  <ENV_RequestMethod>GET</ENV_RequestMethod> 
  <ENV_referer>http://write.blog.csdn.net/postedit</ENV_referer> 
  <chgmobile>15238275006</chgmobile> 
  <city>平顶山</city> 
  <province>河南</province> 
  <retcode>0</retcode> 
  <retmsg>OK</retmsg> 
  <supplier>移动</supplier> 
  <tid /> 
  </root>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值