请问,哪里有在线显示天气预报的代码或网站啊,主要是显示四川省各大城市的天气情况 http://www.t7online.com/China.htm用fopen()获取html文件,然后分析html,提取自己要的信息 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 哈哈,我做出回来了,每隔12小时,重新取一次数据,这样,会减轻网络负担的,<?php/*---- 城市天气预报根据http://www.t7online.com/cgi-bin/citybild?PROVIDER=anwendung&WMO=56294&LANG=cn网站的数据,从结果中进行分析,得到数据,并将数据存放于文件中,采用12小时生成一次,这样,不必每次都重新生成---*///要显示的城市$AryCityCode = array("56294" => "成都", "57206" => "广元", "56196" => "绵阳", "56198" => "德阳", "56386" => "乐山", "56391" => "眉山", "57504" => "内江", "56396" => "自贡", "56491" => "宜宾", "57415" => "广安");//每隔多长时间重新生成数据,小时数$option3 = "12";$file = "other/city_weather.cache"; //天气信息存放文件if(file_exists($file)) { //文件存在 include_once($file); $ctime = time() - $option3 * 60 * 60; if ($ts > $ctime) { //所有城市,未超过更新时间 $action = 1; $str = $str; } else { $action = 0; } } else { $action = 0;}//调用函数,重新更新内容if($action == 0) { //设置系统超长时间 set_time_limit(0); $fp = fopen($file, w); $content = ""; //循环数据,重新生成所有城市的数据 while (list($CityCode, $CityName) = each($AryCityCode)) { $content .= city_weather($CityCode); } //生成时间标识,同时,写进数据文件中 $str = "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"#FFFFFF\" bordercolor=\"#FFFFFF\">".$content."</table>"; $content = "<?\$ts=\"".time()."\";\n\$str='".$str."';\n?>"; fwrite($fp, $content); fclose($fp);}echo $str; //显示天气预报数据//**********************************************//* 功能:根据城市代码,重新生成天气数据//* 来源:原创//* 参数(输入):option1--城市代码 option2--表格单元背景色//* 数据库操作://* 输出:生成新的数据//* 时间:2003-11-21//* 作者:紫文科技 www.zwon.net 王友兴 (网名:海风习习 //* QQ:10196648 [email protected] [email protected])//**********************************************function city_weather($option1, $option2="#F2FDFB"){//from yahoo global $AryCityCode;//更新内容$UrlWeather = "http://www.t7online.com/cgi-bin/citybild?PROVIDER=anwendung&WMO=$option1&LANG=cn";$fp = fopen($UrlWeather, "r");$num = 1; //行数变量初始为1,表示第一行while (!feof($fp)) {//如果大于80行,则退出循环,因此,以后的数据没有用if ($num >= 80) break;$msg = trim(fgets($fp, 4096)); //得到一行的数据//得到天气情况if ($num == 70) { eregi("alt=\".*\" width", $msg, $ary); $weather2 = str_replace("ALT=\"", "", $ary[0]); $weather2 = str_replace("\" width", "", $weather2);}//得到最低温度if ($num == 58) { eregi("<b>([0-9]+)°C</b>", $msg, $ary); $weathermin = str_replace("°C", "", $ary[0]);//替换掉其中的度数表示符号}//得到最高温度if ($num == 64) { eregi("<b>([0-9]+)°C</b>", $msg, $ary); $weathermax = $ary[0];}$num++; //行数变量加1}fclose($fp);$weather = $AryCityCode[$option1]." ".$weather2." 气温:".$weathermin."~".$weathermax;return "<tr><td bgcolor=\"$option2\">$weather</td></tr>\n";}?> 56294" => "成都", "57206" => "广元", "56196" => "绵阳", "56198" => "德阳", "56386" => "乐山", "56391" => "眉山", "57504" => "内江", "56396" => "自贡", "56491" => "宜宾", "57415" => "广安");这些城市代码是怎么得到的?如果我想取其它的城市应该用什么代替呢? http://www.t7online.com/sichuang.htm,这上面有啊,你打开源文件,就可以看到了, php中file_get_contents()是把文件读入一个字符串,在java中有类似功能的函数嘛 请foolbirdflyfirst进来一下,问个问题 php动态生成数组元素问题 求助:编译php出错 会asp.net C#,公司是LINUX系统,是转JSP快还是PHP快? 模板类一问:无论哪种模板类的模板内容,是不是都是一样的? 啊,郁闷,装php5出问题 session问题 如何让PHP支持MySQL数据库?以及用户验证http500错误问题。php扩展库哪里有? 怎么让这里提示的是中文呢?有办法吗?新手见笑了 关键问题!请大家帮忙 为何我的$_GET['name']取不了数据???
/*---- 城市天气预报
根据http://www.t7online.com/cgi-bin/citybild?PROVIDER=anwendung&WMO=56294&LANG=cn
网站的数据,从结果中进行分析,得到数据,并将数据存放于文件中,采用12小时生成一次,这样,不必每次都重新生成---*///要显示的城市
$AryCityCode = array(
"56294" => "成都",
"57206" => "广元",
"56196" => "绵阳",
"56198" => "德阳",
"56386" => "乐山",
"56391" => "眉山",
"57504" => "内江",
"56396" => "自贡",
"56491" => "宜宾",
"57415" => "广安");//每隔多长时间重新生成数据,小时数
$option3 = "12";$file = "other/city_weather.cache"; //天气信息存放文件
if(file_exists($file)) {
//文件存在
include_once($file);
$ctime = time() - $option3 * 60 * 60;
if ($ts > $ctime) {
//所有城市,未超过更新时间
$action = 1;
$str = $str;
} else {
$action = 0;
}
} else {
$action = 0;
}//调用函数,重新更新内容
if($action == 0) {
//设置系统超长时间
set_time_limit(0);
$fp = fopen($file, w);
$content = "";
//循环数据,重新生成所有城市的数据
while (list($CityCode, $CityName) = each($AryCityCode)) { $content .= city_weather($CityCode); }
//生成时间标识,同时,写进数据文件中
$str = "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"#FFFFFF\" bordercolor=\"#FFFFFF\">".$content."</table>";
$content = "<?\$ts=\"".time()."\";\n\$str='".$str."';\n?>";
fwrite($fp, $content);
fclose($fp);
}echo $str; //显示天气预报数据//**********************************************
//* 功能:根据城市代码,重新生成天气数据
//* 来源:原创
//* 参数(输入):option1--城市代码 option2--表格单元背景色
//* 数据库操作:
//* 输出:生成新的数据
//* 时间:2003-11-21
//* 作者:紫文科技 www.zwon.net 王友兴 (网名:海风习习
//* QQ:10196648 [email protected] [email protected])
//**********************************************
function city_weather($option1, $option2="#F2FDFB"){
//from yahoo
global $AryCityCode;//更新内容
$UrlWeather = "http://www.t7online.com/cgi-bin/citybild?PROVIDER=anwendung&WMO=$option1&LANG=cn";
$fp = fopen($UrlWeather, "r");$num = 1; //行数变量初始为1,表示第一行while (!feof($fp)) {
//如果大于80行,则退出循环,因此,以后的数据没有用
if ($num >= 80) break;$msg = trim(fgets($fp, 4096)); //得到一行的数据//得到天气情况
if ($num == 70) {
eregi("alt=\".*\" width", $msg, $ary);
$weather2 = str_replace("ALT=\"", "", $ary[0]);
$weather2 = str_replace("\" width", "", $weather2);
}//得到最低温度
if ($num == 58) {
eregi("<b>([0-9]+)°C</b>", $msg, $ary);
$weathermin = str_replace("°C", "", $ary[0]);//替换掉其中的度数表示符号
}//得到最高温度
if ($num == 64) {
eregi("<b>([0-9]+)°C</b>", $msg, $ary);
$weathermax = $ary[0];
}$num++; //行数变量加1
}
fclose($fp);$weather = $AryCityCode[$option1]." ".$weather2." 气温:".$weathermin."~".$weathermax;return "<tr><td bgcolor=\"$option2\">$weather</td></tr>\n";}
?>
"57206" => "广元",
"56196" => "绵阳",
"56198" => "德阳",
"56386" => "乐山",
"56391" => "眉山",
"57504" => "内江",
"56396" => "自贡",
"56491" => "宜宾",
"57415" => "广安");这些城市代码是怎么得到的?如果我想取其它的城市应该用什么代替呢?