• 26-08-2010, 11:06:29
    #1
    Bu yazıda google sunduğu hava durumu hizmetini botlayarak kendi sitemizde nasıl kullanabileceğimizi göstericez.

    <?
    Class erguner 
    {
        function dayadd($days,$date=null , $format="d/m/Y"){
            // add days to a date
            return date($format,strtotime($days." days",strtotime( $date ? $date : date($format) )));
        }
        private function attr($s,$attrname) {
            //retrn html attribute
            preg_match_all('#\s*('.$attrname.')\s*=\s*["|\']([^"\']*)["|\']\s*#i', $s, $x); 
            if (count($x)>=3) return $x[2][0];
            return "";
        }
    public function hava($q,$thedate="") {
    
      //(teşekkürler google)
      if (!$thedate) $date = date("Y-m-d"); //bugün
       else $date = $thedate;
      if ($date>$this->dayadd(3,date("Y-m-d"),"Y-m-d"))return "";
      // verileri alalım
      $web_page = file_get_contents( "http://www.google.com.tr/search?q=weather+" . urlencode($q) );
      //parçalayalım
      preg_match_all('#<div class=e>(.*)</table>#Us', $web_page, $m);
      if (count($m)>0) {
       
       $p = array();
       preg_match_all('#<img([^>]*)?>#Us', $m[0][0], $img);
       for ($i=0;$i<count($img[0]);$i++) {
        $tag = str_replace("src=\"/","src=\"http://www.google.it/",$img[0][$i]);
        $p[$i]["date"]=$this->dayadd($i,date("Y-m-d"),"Y-m-d");
        $p[$i]["title"] = $this->attr($tag,"title");
        $p[$i]["img"] = $this->attr($tag,"src");
       }
       preg_match_all('#<nobr>(.*)</nobr>#Uis', $m[0][0], $nobr);
       for ($i=0;$i<count($nobr[1]);$i++) {
        $temp= explode("|",$nobr[1][$i]);
        $p[$i]["min"] = trim($temp[1]) ;
        $p[$i]["max"] = trim($temp[0]) ;
       }
       return (!$thedate?$p:$p[$date]);
      }
      return array();
     }
     }
    ?>
    Yukarıdaki dosyayı hava.fonk.php olarak kaydedelim. Daha sonra,
       <?
    include "hava.fonk.php"; //Fonksiyonumuz
    $c = "Bursa"; //Şehir
    $erguner = new erguner;
    $go = $erguner->hava($c); echo "<h1>".$c." hava durumu</h1>".$go[0][date]."<br>".$go[0][title]."<br><img src='".$go[0][img]."'><br>".$go[0][min]."<br>".$go[0][max];
    ?>
    Yukarıdaki dosyayı da hava.php olarak kaydedelim ve hava.php yi çalıştıralım…
    Resimli olarak bulunduğumuz günün hava durumu karşınızda!

    KAYNAK : http://www.erguner.net/php/fonksiyon...le-hava-durumu
  • 26-08-2010, 11:46:54
    #2
    Üyeliği durduruldu
    botlayarak wonderful
  • 26-08-2010, 11:55:04
    #3
    Öncelikle teşekkürler. Denedim fakat bir hata çıktı, sebebi ne olabilir ?

    Alıntı
    Fatal error: Using $this when not in object context in /home/aaa/public_html/hava.fonk.php on line 6
  • 26-08-2010, 11:56:29
    #4
    botlayarak.com < wonderful idea!
  • 26-08-2010, 11:57:14
    #5
    antishareware adlı üyeden alıntı: mesajı görüntüle
    Öncelikle teşekkürler. Denedim fakat bir hata çıktı, sebebi ne olabilir ?
    safe_mode OFF
    open_basedir OFF
    ve
    sunucunda cURL kurulumu ?!?
  • 26-08-2010, 12:20:50
    #6
    Şu anda çalıştı hocam, teşekkürler.