该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
为了服务器安全着想,所以把allow_url_fopen关掉了。
当服务器allow_url_fopen = Off 时,就不能用file_get_contents,只有设置ON时可以用。
$getstr=file_get_contents("http://www.163.com/weatherxml/54511.xml");
$qx=explode("\"",strstr($getstr,"qx="));
$wd=explode("\"",strstr($getstr,"wd="));
$qximg=explode("\"",strstr($getstr,"qximg="));
$qximg_=explode(",",$qximg[1]);
echo "北京 ".$qx[1]."";
echo $wd[1];*/
//echo "";
?>
以下是通curl_init函数来获取163天气预报
把php.ini里( ;extension=php_curl.dll ) 前面的(;)去掉保存
把php_curl.dll,libeay32.dll,ssleay32.dll拷到c:\windows\system32里,重启IIS即可,没有装apache
//初始化curl
$ch = curl_init() or die (curl_error());
//设置URL参数
curl_setopt($ch,CURLOPT_URL,"http://www.163.com/weatherxml/54511.xml");
//要求CURL返回数据
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
//执行请求
$result = curl_exec($ch) or die (curl_error());
//取得返回的结果,并显示
//echo $result;
// echo curl_error($ch);
$qx=explode("\"",strstr($result,"qx="));
$wd=explode("\"",strstr($result,"wd="));
$qximg=explode("\"",strstr($result,"qximg="));
$qximg_=explode(",",$qximg[1]);
echo "北京 ".$qx[1]."
";
echo $wd[1];
//关闭CURL
curl_close($ch);
?>