$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>