Maison  >  Article  >  développement back-end  >  PHP天气预报小偷08年版_PHP

PHP天气预报小偷08年版_PHP

WBOY
WBOYoriginal
2016-06-01 12:25:12926parcourir

/************************************************************************
名称:天气预报小偷
功能:每天读取新浪网上的天气情况并保存到本地,然后再从本地读取显示
开发:n3tl04d QQ:10492315 1妹儿:n3tl04d[at]gmail.com [url]http://smboy.bokee.com[/url]
更新日期:2007年11月22日
*************************************************************************/
@header("Content-Type:text/html;charset=gb2312");
 error_reporting(0);

/*******************看weather.txt的修改时间是否为当天,如果是昨天的就要上网抓结果***********/
     $tmp = filemtime("weather.txt");
    $tt1=date("Ymd",$tmp)."
";
    $tt2=date("Ymd");
    if ($tt1    //echo "要抓结果";
    unlink("weather.txt");
    $url = "http://php.weather.sina.com.cn/search.php?city=广州" ;
    $content = file_get_contents($url);
    preg_match_all('/

(.+?)/si',$content,$result);
    for($i=0;$i        $x= strip_tags($result[1][$i])."\n";
        $handle = fopen ("weather.txt", "a");
            fwrite($handle, $x);
         fclose($handle);

      }
      listweather();
  
    } else {
        // echo "直接从weather.txt读结果";   
        listweather();
    }

    //天气显示函数
    function listweather() {
    $filename="weather.txt";
    $handle=fopen($filename,"r");

    if ($handle) {   
        $contents=fread($handle,filesize($filename));
        fclose($handle);
        $cc=explode("\n",$contents);
        $today=explode(" ",$cc[0]);
        $tomo=explode(" ",$cc[1]);
?>


 
   

     
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn