文本版|topic 高级搜索
   名人堂 帮助 论坛制度 意见反馈 | 首页 博客 周新贴 招聘 专题 新闻
RSS 底部
 
社区导航: 专家门诊   网络技术   操作系统   数据库   程序设计   系统应用   考试认证   CIO及信息化   站长交流   综合交流   下载基地  51CTO产品服务 设为首页 | 收藏本站
51CTO技术论坛» Php » 改进后的《自动显示天气预报》小程序       [ 打印]  [ 订阅]  [ 收藏]  [ 推荐给朋友]   [ 本帖文本页]

论坛跳转:
     
标题: [转载] 改进后的《自动显示天气预报》小程序  ( 查看:194  回复:0 )   
 
dada00001
技术员  点击可查看详细



帖子 64
精华 1
无忧币 360
积分 350
阅读权限 30
注册日期 2007-8-16
最后登录 2007-11-1 离线

[查看资料]  [发短消息]  [Blog
       
发表于:2007-8-20 09:59   标题:改进后的《自动显示天气预报》小程序
上一帖 |
这次改进,主要是增加了图象的获取,并提供了一个比较完整的获取远端文件的函数。具体代码如下:
<?
$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);
}
?>



网络工程师到底该不该去考CCIE认证?
2007-8-20 09:591楼
[ 顶部 ]
     
论坛跳转:  

| | |

标记已读 · 删除论坛Cookies · 文本版 · WAP
 
| 诚征版主 | 版主堂 | 意见建议 | 大史记 | 论坛地图
Copyright©2005-2008 51CTO.COM  Powered by Discuz!
本论坛言论纯属发布者个人意见,不代表51CTO网站立场!如有疑义,请与管理员联系。
京ICP备05051492号