<?
$city="西安";    //这里设置城市数据//远程打开新浪的天气预报页面
$filename="http://weather.sina.com.cn/index.html";
$fp=fopen($filename,"r");
$www=fread($fp,100000);//取得第一个时间
$riqi=strstr($www,"<td colspan=3>");
$num=strpos($riqi,"</td>")-strlen("<td colspan=3>");
$riqi=substr($riqi,strlen("<td colspan=3>"),$num);
//取得第二个时间
$riqi2=strstr($www,"colspan=3>");
$riqi2=strstr($riqi2,"<td colspan=3>");
$num=strpos($riqi2,"</td>")-strlen("<td colspan=3>");
$riqi2=substr($riqi2,strlen("<td colspan=3>"),$num);//取得预报的数据
$city="<td>".$city."</td>";
$www=strstr($www,$city);
$ender="</tr>";
$num=strpos($www,$ender);
$www=substr($www,0,$num);//=========处理预报数据开始========
$www=substr($www,4);
$www=explode("<td>",$www);//定义处理函数
function sub($x)
{
$num=strpos($x,"</td>");
$real=substr($x,0,$num);
return $real;
}//处理数据
$www[1]=sub($www[1]); //时间一天气状况
$www[2]=sub($www[2]); //时间一风向风力
$www[3]=sub($www[3]); //时间一最低温度
$www[4]=sub($www[4]); //时间二天气状况
$www[5]=sub($www[5]); //时间二风向风力
$www[6]=sub($www[6]); //时间二最高温度//=========处理预报数据完成========//格式化输出,了解html的兄弟可以直接修改 嘿嘿.
echo "<font size=2 color=red>";
echo $city."市天气预报:";
echo $riqi;//时间一
echo "&nbsp";
echo $www[1];
echo "&nbsp风力风向:&nbsp";
echo $www[2];
echo "&nbsp最低温度:&nbsp";
echo $www[3];
echo "&nbsp&nbsp&nbsp";
echo $riqi2;//时间二
echo "&nbsp";
echo $www[4];
echo "&nbsp风力风向:&nbsp";
echo $www[5];
echo "&nbsp最高温度:&nbsp";
echo $www[6];
echo "</font>";?>