大家帮我看看这段PHP程序。。。

waiyan 2005-01-18 10:01:53
能注释下以下一段程序吗?特别是取网页内容那段。

function getWeather($mobile /*手机号*/,$path=1 /*1-今天 2-明天 3-后台*/)
{
$whichday = $path * 24;
$region['华北'] = 'hb';
$region['东北'] = 'db';
$region['华南'] = 'hn';
$region['华东'] = 'hd';
$region['华中'] = 'hz';
$region['西北'] = 'xb';
$region['西南'] = 'xn';

$day = date('Y-m-d');
$day = getEndDate($day,$path - 1,'D');
$time = date('H');
$title[0] = $day.'白天';
$title[1] = '风向风力';
$title[2] = '最高温度';
$title[3] = ' 夜晚';
$title[4] = '风向风力';
$title[5] = '最低温度';
/*$area = getWeatherArea($mobile); //得到手机属地*/
/*if (!$area)
{
$area['Area']='华北';
$area['City']='北京';
$area['Province'] = '北京';
}*/

$area['Area']='华南';
$area['City']='福州';
$area['Province'] = '福建';
//新浪天气预报链接
$sURL= "http://weather.news.sina.com.cn/gn".$region[$area['Area']].$whichday."w.html";
//$sURL = "http://weather.news.sina.com.cn/gnhb24w.html";
list($protocol, $sURL) = explode('://', $sURL); // separa o resto
list($host, $foo) = explode('/', $sURL); // pega o host
list($foo, $request) = explode($host, $sURL); // pega o request
list($host, $port) = explode(':', $host); // pega a porta

if ( strlen($request) == 0 ) $request = "/";
if ( strlen($port) == 0 ) $port = "80";

$httpHeader = "GET $request HTTP/1.0\r\n";
$httpHeader .= "Host: $host\r\n";
$httpHeader .= "Connection: Close\r\n";
$httpHeader .= "User-Agent: cHTTP/0.1b (incompatible; M$ sucks; Open Source Rulez)\r\n";
$httpHeader .= "\r\n\r\n";
$fp = fsockopen($host, $port,$errno,$errstr,15);
$result = "";
if ( $fp ) {
fwrite($fp, $httpHeader);
while(! feof($fp)) { //读取get的结果
$result .= fread($fp, 1024);
}
fclose($fp);


//下面是分析结果,提取天气预报信息
$seperator = $area['Area']."地区";
$sections = explode($seperator,$result);
$content = explode($area['Province?].'</td>',$sections[2]);
if (sizeof($content) == 3)
$tmp = $content[2];
else
list($foo,$tmp) = explode($area[City'].'</td>',$content[1]);

$posTr = strpos($tmp,'</tr>');
$tmp = substr($tmp,0,$posTr);
$lines = explode('</td>',$tmp);

$str = "";
$middle = array();
for($i = 0; $i < count($lines); $i++)
{
$line = preg_replace("/[\s ]+/","",$lines[$i]);
if($line != "")
{
$line = ereg_replace("<td>","",$line);
if ($i == 1 || $i == 4)
$middle[$i] = $line."级";
else if ($i == 2 || $i == 5)
{
$middle[] = substr($line,0,2)."度";
//$temp[] = $middle;
if ($i == 5)
{
if (strcmp($middle[2],$middle[5]) <= 0)
{
$tmp = $middle[2];
$middle[2] = $middle[5];
$middle[5] = $tmp;
}
}
}
else
$middle[$i] = $line;
//$str .= ",".$title[$i].$middle;
}
}
for($i = 0;$i < count($middle); $i++)
{
$str .= ",".$title[$i].$middle[$i];
}
$str = $area['City'].str_replace("≤","",$str);
$str = str_replace(" ","",$str);
//echo $str."--<br>";
return $str;
}
...全文
103 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧