LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 662|回复: 1

PHP数组的急问题

[复制链接]
发表于 2005-6-10 20:37:21 | 显示全部楼层 |阅读模式
<code>
<?php

class weather
{
        var  $weather=array("","","","","");



        function weather()
        {
                $fcont=@file_get_contents("http://www.tq121.com.cn/forecast/cf.php");
                $data=explode("<font color=\"#FF0000\">", $fcont);
                $fdate=substr($data[1],2,18);
                $city=explode("461,292,498,308", $fcont);
                $fcast=$city[1];
                $fcastarr=explode("<br>", $fcast);
                $wea[0]=chop(substr($fcastarr[0],-5,5));
                $wea[1]=chop(substr(trim($fcastarr[1]),5));
                $wea[2]=chop(substr(trim($fcastarr[2]),5));
                $wea[3]=chop(substr(trim($fcastarr[3]),5));
                $wea[4]=chop(substr(trim($fcastarr[4]),5));
                $this->$weather[0]=$wea[0];
                $this->$weather[1]=$wea[1];

         }


}
?>

<?PHP
$kkk=new weather;
print $kkk->$weather[0];
</code>


$weather[0]应该是"上海"
$weather[1]应该是天气情况.
为什么输入的情况却是.$weather[0]和weather[1]相同呢.
发表于 2005-6-11 20:15:44 | 显示全部楼层
$fcont = @file_get_contents("http://www.tq121.com.cn/forecast/cf.php");

$date = explode("<font color=\"#FF0000\">", $fcont);
$fdate = substr($date[1],2,18);

$city = explode("461,292,498,308", $fcont);
$fcast = $city[1];
$fcastarr = explode("<br>",$fcast);
$weather["天气"] = substr(trim($fcastarr[1]),5);
$weather["温度"] = substr(trim($fcastarr[2]),5);
$weather["风向"] = substr(trim($fcastarr[3]),5);
$weather["风力"] = substr(trim($fcastarr[4]),5);
//print_r($weather);
$pic = "sunny.jpg";
if (strstr($weather["天气"],"晴"))
        $pic = "sunny.jpg";
elseif (strstr($weather["天气"],"多云"))
        $pic = "cloudy.jpg";
elseif (strstr($weather["天气"],"雾"))
        $pic = "foggy.jpg";
elseif (strstr($weather["天气"],"雹"))
        $pic = "frezz.jpg";
elseif (strstr($weather["天气"],"雨"))
        $pic = "rain.jpg";
elseif (strstr($weather["天气"],"雪"))
        $pic = "snow.jpg";
elseif (strstr($weather["天气"],"雨加雪"))
        $pic = "mixed.jpg";
elseif (substr($weather["风力"],1) >= 5)
        $pic = "windy.jpg";
?>
<body style="text-align:center;font-size:14px;font-family:Arial">
上海-<span style="color:red"><? echo $fdate; ?></span>发布的最新天气预报:<br><br>
<img src="images/<? echo $pic; ?>">
<br>
<br>
<? echo $weather["天气"]; ?>,<? echo $weather["温度"]; ?>,风力:<? echo $weather["风力"]; ?>,风向:<? echo $weather["风向"]; ?>
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表