php读取远程xml文件简单方法
<?php$wd=贵阳$para=$_REQUEST["wd"];$q="http://webservice.webxml.com.cn/WebServices/Weat...
<?php
$wd=贵阳
$para=$_REQUEST["wd"];
$q="http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getWeather?&theUserID=&theCityCode=$para";
$xml_array=simplexml_load_file($q); //将XML中的数据,读取到数组对象中
foreach($xml_array as $tq){
echo $tq;
}
?>
请问下我写的方式能否读取到网址中的内容 展开
$wd=贵阳
$para=$_REQUEST["wd"];
$q="http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getWeather?&theUserID=&theCityCode=$para";
$xml_array=simplexml_load_file($q); //将XML中的数据,读取到数组对象中
foreach($xml_array as $tq){
echo $tq;
}
?>
请问下我写的方式能否读取到网址中的内容 展开
2015-05-28
展开全部
<?php
set_time_limit(0);
function _rand() {
$length=26;
$chars = "0123456789abcdefghijklmnopqrstuvwxyz";
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
$string = '';
for($i = 0; $i < $length; $i++) {
$string .= $chars[mt_rand(0, $max)];
}
return $string;
}
$HTTP_SESSION=_rand();
$HTTP_SESSION;
$ch = curl_init();
curl_setopt ($ch,CURLOPT_URL,"http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getWeather?&theUserID=&theCityCode=贵港");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
$res = curl_exec($ch);
curl_close ($ch);
//print_r($res);
$xml_array=simplexml_load_string($res);
// www.hi-docs.com/php/simplexml_load_string.html
foreach($xml_array as $tq){
echo $tq;
}
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询