动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   PHP → 阅读文章

 改进后的《自动显示天气预报》小程序(Linux和Windows环境都可以)

作者来源: 
阅读 数 522 人次 , 2006-4-18 17:15:00 


   这次改进,主要是增加了图象的获取,并提供了一个比较完整的获取远端文件的函数。具体代码如下:
<?
$fcont=file("http://www.bjmb.gov.cn/today.asp");
$arr=array();
for($i=0;$i<count($fcont);$i++){
    $tmp=$fcont[$i];
    $tmp=ereg_replace("<br>"," ",$tmp);
    if(!strstr(strtolower($tmp),"img")){
        $tmp=trim(strip_tags($tmp));
    } else {
        $st=ereg_replace("><",">⌒<",$tmp);
        $stt=split("⌒",$st);
        foreach($stt as $key => $value){
            if(strstr($value,"img") ){
                $tmp=$value;
                if(strstr($tmp,"bt9.jpg") || strstr($tmp,"colline.gif")){
                    $tmp="";
                }else{
                    $tmp=ereg_replace("\"","",$tmp);
                    $st=split("src=",$tmp);
                    $st1=split(" ",$st[1]);getpic("http://www.bjmb.gov.cn/$st1[0]","image");
                    if(count($st)>2){
                    $st2=split(" ",$st[2]);getpic("http://www.bjmb.gov.cn/$st1[0]","image");
                    }
                    $tmp=ereg_replace("src=","width=30 height=30 align=absmiddle src=",$tmp);
                }
            }
        }
    }
    if(trim($tmp)!="" && trim($tmp)!=" ") $arr[]=$tmp;
}
$yb=array();
for($i=2;$i<count($arr)-6;$i++){
    $yb[]=$arr[$i];
}
?>
<br>
<SCRIPT LANGUAGE="JavaScript">
<!--
syb="";
<?
$exp="-3-7-9-14-18-20-25-";
for ($i=1;$i<count($yb);$i++){
    if (!strstr($exp,"-".(string)($i+1)."-")){
?>
    syb=syb+'<?=$yb[$i];?> ';
<?}}?>
document.write("<?=$yb[0]?>"+":");
document.write("<marquee width=400 align=middle scrollamount=5 scrolldelay=200>"+syb+"预报</marquee>");
//-->
</SCRIPT>
<?
function getpic($url,$dir){
    $tmp=split("/",$url);
    $fname=$tmp[count($tmp)-1];
    if(strstr($dir,"\\")){
        if(substr($dir,-2)=="\\") $file=$dir.$fname;else $file=$dir."\\".$fname;
    }else{        
        if(substr($dir,"/")){
            if(substr($dir,-1)=="/") $file=$dir.$fname;else $file=$dir."/".$fname;
        }
        else{
            return ;
        }
    }
    if(!(file_exists("$dir") && is_dir("$dir"))) mkdir($dir,0777);
    if(file_exists($file)) return ;
    $fpo=fopen($file,"wb");
    if(!$fpo) return ;
    $num=0;
    do{
        $num++;
        $fpi=fopen($url,"r");
    }while(!$fpi && $num<3);
    if(!fpi)    return ;
    while(!feof($fpi)){
        $cont=fread($fpi,128);
        fwrite($fpo,$cont,128);
    }
    fclose($fpi);
    fclose($fpo);
}
?>   
 本文TagsWindows  linux  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:web方式ftp,建议加入精华区,嘿嘿
· 下一篇:初学PHP,编写了一个显示天气预报的程序,还望不要见笑。
· PHP4实际应用经验篇(4)
· PHP 4.1.0 出版公告(中英对照版)
· 关于session的几个补充函数 (转)
· 帮你免于失业的十大软件技术
· 正则表达式例子:获得某个网页上的所有超裢接


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077