QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1450|回复: 5

PHP数组的急问题

[复制链接]
发表于 2005-6-10 20:34:28 | 显示全部楼层 |阅读模式
<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,1;
                $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-10 22:08:51 | 显示全部楼层
跟踪$wea[1]=chop(substr(trim($fcastarr[1]),5))的值

从http://www.tq121.com.cn/forecast/cf.php获得的天气预报是否保证了数据的一一对应
回复

使用道具 举报

 楼主| 发表于 2005-6-13 10:24:47 | 显示全部楼层
在$wea[]中的值是一一对应的.可是到了$weather中的时候就不对了.
回复

使用道具 举报

发表于 2005-6-13 21:47:49 | 显示全部楼层
$this->$weather[0]=$wea[0];
$this->$weather[1]=$wea[1];

好像不是这么用吧?
很久不用了………
回复

使用道具 举报

 楼主| 发表于 2005-6-15 15:46:57 | 显示全部楼层
[quote:3c3c308fe6="jiangtao9999"]
$this->$weather[0]=$wea[0];
$this->$weather[1]=$wea[1];

好像不是这么用吧?
很久不用了………[/quote]

那应该怎么用的啊。????
回复

使用道具 举报

发表于 2005-6-15 17:06:41 | 显示全部楼层
echo $kkk->weather;
回复

使用道具 举报

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

本版积分规则

GMT+8, 2024-4-20 08:51 , Processed in 0.155918 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

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