麻辣堂|资源主站|开发论坛|在线手册
首页 Apache Linux Java MySQL 注册帮助 
PHP项目开发组是PHP开发资源网于2007组年建成立的项目开发团队,目前核心开发成员有27人, 项目协作成员8名.下设7个开发组,主要承接大/中型网站项目开发任务。

    由于开发任务较多,人员比较紧张,现面向社会招聘全职或者兼职开发人员,不管你是在校大学生,还是全职开发人员,以及SOHO都可以联系本站,我们可以长期合作,并为您带来丰厚的报酬。
  您现在的位置:PHP开发资源网 > 麻辣堂 > 详细资料
待解决
Qq天气预报小偷类 1.1.0
悬赏分:20 - 2007年08月15日

数据取自QQ天气预报。
带缓存功能,每天只取一次数据。速度很快。

CODE:
<?php

/*
+---------------------------------------------------+
| Name : NeatQQWeatherClass (QQ天气预报小偷类)
+---------------------------------------------------+
| Created / Modify : 2003-10-10 / 2004-10-11
+---------------------------------------------------+
| Version : 1.1.0
+---------------------------------------------------+
| Author : walkerlee
+---------------------------------------------------+
| Powered by NEATSTUDIO 2002 - 2004
+---------------------------------------------------+
| Email : [email]neatstudio@yahoo.com.cn[/email]
| Homepge : [url]http://www.neatstudio.com[/url]
| BBS : [url]http://www.neatstudio.com/bbs/[/url]
+---------------------------------------------------+
| Note :
|
| 1.本软件对于非商业用户完全免费,如果要使用在商业用途
| 方面,必须取得作者的授权.
|
| 2.你可以任意传播以及修改本程序,但不能以任何形式删除
| 本程序的版权.请记住,保留作者版权是对作者工作的尊敬.
|
| 3.如果有问题,可以通过上面提供的方式进行解答,但作者
|
| 如果不能及时或者不解答,请谅解.
|
| 4.作者对使用该程序导致的问题,不予以负责.
|
| 5.本程序版权归 NeatStudio 所有.禁止任何侵权行为!
|
+---------------------------------------------------+
| 支持城市 :
+---------------------------------------------------+
| 北京
| 上海
| 天津
| 石家庄
| 哈尔滨
| 沈阳
| 长春
| 太原
| 济南
| 郑州
| 呼和浩特
| 西安
| 银川
| 兰州
| 西宁
| 乌鲁木齐
| 合肥
| 南昌
| 南京
| 杭州
| 武汉
| 长沙
| 广州
| 深圳
| 福州
| 厦门
| 南宁
| 桂林
| 海口
| 重庆
| 成都
| 贵阳
| 昆明
| 拉萨
| 香港
| 澳门
| 台北
+---------------------------------------------------+
*/

class NeatQQWeather
{

/*
+----------------------+
| 配置
+----------------------+
*/

var $url;
var $contents = "";

function NeatQQWeather($city_name)
{
$this->url = 'http://appnews.qq.com/cgi-bin/news_weather_search?city=' . $city_name;

$this->cache();

}

/*
+----------------------+
| 取页面
+----------------------+
*/

function getPage()
{
$this->contents = file_get_contents($this->url);
}

/*
+----------------------+
| 取数据
+----------------------+
*/

function getData()
{
preg_match_all("/<td width=\"20\" class=\"text02\"> &nbsp;&nbsp;<font color=\"#FF0000\">●<\/font><\/td>\r\n <td class=\"text02\">\r\n(.*?)\r\n <\/td>\r\n <\/tr>\r\n <\/table><\/td>/is", $this->contents, $this->tcity);

preg_match_all("/<div align=\"center\"><font color=\"#FFFFFF\">(.*?)<\/font><\/div>/is", $this->contents, $this->tdate);

preg_match_all("/<img src=\"\/images\/weather_p(.*?).gif\" width=\"23\" height=\"23\">(.*?)<\/div>/is", $this->contents, $this->tweather);

preg_match_all("/<div align=\"center\">风向风力<\/div><\/td>\r\n <td bgcolor=\"#FFFFFF\" class=\"text02\"> <div align=\"center\">(.*?)<\/div>/is", $this->contents, $this->twind);

preg_match_all("/最低气温\(℃\)<\/div><\/td>\r\n <td height=\"22\" bgcolor=\"#FFFFFF\" class=\"text02\"><div align=\"center\">(.*?)<\/div><\/td>/is", $this->contents, $this->tlow);

preg_match_all("/最高气温\(℃\)<\/div><\/td>\r\n <td bgcolor=\"#FFFFFF\" class=\"text02\"><div align=\"center\">(.*?)<\/div><\/td>/is", $this->contents, $this->thight);
}

function fetchData()
{
return $this->data;
}

/*
+----------------------+
| 整理数据
+----------------------+
*/

function makeArray()
{
$this->data['city'] = trim($this->tcity[1][0]);

$this->data['stat']['today']['date'] = $this->tdate[1][0];
$this->data['stat']['tomorrow']['date'] = $this->tdate[1][1];

$this->data['stat']['today']['img'] = "<img src=\"http://appnews.qq.com/images/weather_p" . $this->tweather[1][0] . ".gif\" width=\"23\" height=\"23\">";
$this->data['stat']['tomorrow']['img'] = "<img src=\"http://appnews.qq.com/images/weather_p" . $this->tweather[1][1] . ".gif\" width=\"23\" height=\"23\">";

$this->data['stat']['today']['img_url'] = "http://appnews.qq.com/images/weather_p" . $this->tweather[1][0] . ".gif";
$this->data['stat']['tomorrow']['img_url'] = "http://appnews.qq.com/images/weather_p" . $this->tweather[1][1] . ".gif";

$this->data['stat']['today']['weather'] = $this->tweather[2][0];
$this->data['stat']['tomorrow']['weather'] = $this->tweather[2][1];

$this->data['stat']['today']['wind'] = $this->twind[1][0];
$this->data['stat']['tomorrow']['wind'] = $this->twind[1][1];

$this->data['stat']['today']['low'] = $this->tlow[1][0];
$this->data['stat']['tomorrow']['low'] = $this->tlow[1][1];

$this->data['stat']['today']['hight'] = $this->thight[1][0];
$this->data['stat']['tomorrow']['hight'] = $this->thight[1][1];
}


/*
+----------------------+
| 调试模式
+----------------------+
*/

function debug()
{
echo "<pre>";
print_r($this->data);
echo "</pre>";
}

/*
+----------------------+
| 缓存数据
+----------------------+
| 2004-10-11
+----------------------+
*/

function cache()
{
if(file_exists("./NQWCache.php"))
include_once("./NQWCache.php");

$this->cacheToFile();
}

function cacheToFile()
{

if (empty($this->cacheCreateDate) || (date("YmdHis") - $this->cacheCreateDate > 1000000))
{
$this->getPage();
$this->getData();
$this->makeArray();

if (is_writeable('./'))
{
$cacheFile .= "&lt;?php\r\n\r\n";
$cacheFile .= "/*\r\n";
$cacheFile .= "+----------------------------------+\r\n";
$cacheFile .= "| Powered By NeatQQWeatherClass\r\n";
$cacheFile .= "+----------------------------------+\r\n";
$cacheFile .= "| Cache file\r\n";
$cacheFile .= "+----------------------------------+\r\n";
$cacheFile .= "*/\r\n\r\n";
$cacheFile .= "\$this->cacheCreateDate = " . date("YmdHis") . ";\r\n\r\n";
$cacheFile .= "\$this->data = " . $this->arrayeval($this->data);
$cacheFile .= "?&gt;";

$fp = fopen("./NQWCache.php", "w+");
fwrite($fp, $cacheFile);
fclose($fp);

header("location:".$_SERVER['PHP_SELF']);
}
}
}


function arrayeval($array, $level = 0)
{
for($i = 0; $i <= $level; $i++)
{
$space .= "\t";
}
$evaluate = "Array\n$space(\n";
$comma = "$space";
foreach($array as $key => $val)
{
$key = is_string($key) ? "'".addcslashes($key, '\'\\')."'" : $key;
$val = is_string($val) ? "'".addcslashes($val, '\'\\')."'" : $val;
if(is_array($val))
{
$evaluate .= "$comma$key => ".$this->arrayeval($val, $level + 1);
}
else
{
$evaluate .= "$comma$key => $val";
}
$comma = ",\n$space";
}
$evaluate .= "\n$space)";
return $evaluate;
}

}
/*
$NQW = new NeatQQWeather('南宁');
$NQW->debug();
*/
?&gt;

提问者:walker   08-15 09:09
答复
路过。。。顺便帮顶:)
回答者:玉米づ冰冻可乐 - 瓦岗村民 8-22 09:10
我也来回答:
不管你有没有帮助我们,瓦岗寨8万村民将感谢你。。。。。

为防止灌水,您需要计算一道数学题: 答案:
76 + 82 = ? 请将计算结果填在上面

 
[]
©2007 PhpRes.COM