<?php
/*
* Copyright (C) 2003 rIppA (rippa@game4ever.de)
* [url]http://codebase.game4ever.de[/url]
* 07.08.2003
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*******************************************************************************
* Syntax: wetter("12345") // PLZ
*
*
* Anwendungsbeispiel :
$wetter = wetter("12345");
$error = $wetter["error"]; // (1/0) wenn 1: fehler -> keine daten
$error_msg $wetter["msg"]; // fehlertext
// wenn kein fehler aufgetreten ist:
$plz = $wetter["plz"]; // plz
$stadt = $wetter["stadt"]; // gefundener stadt-name
$akt_temp = $wetter["akt_temp"]; // aktuelle temperatur
$max_temp = $wetter["max_temp"]; // max. temperatur
$min_temp = $wetter["min_temp"]; // min. temperatur
$niederschlag = $wetter["niederschlag"]; // niederschlagswahrscheinlichkeit
*
*
*
*/
function wetter($params) {
$buffer = '';
$url = "http://www.wetter.com";
$suchseite = $url . "/home/structure/control.php?sessionID=&Lang=DE&ms=1&ss=1&sss=2&search=" . $params;
if ($fp = fsockopen ("www.wetter.com", 80, $errno, $errstr, 30)) {
fputs ($fp, "GET $suchseite HTTP/1.0\r\nHost: Search\r\n\r\n");
while (!feof($fp)) $buffer .= fgets ($fp, 1024);
fclose ($fp);
if (preg_match('/Diese Postleitzahl ist uns leider nicht bekannt/is', $buffer)) {
# unbekannte plz
$return["error"] = 1;
$return["msg"] = "wetter infos: unbekannte PLZ!";
return $return;
} else {
if (preg_match('/PLZ-SUCHE/is',$buffer)) {
preg_match('/<div class="tabHeadline">\((.+?) Treffer\)<\/div><\/td>(.+?)<td colspan="3"><a href="control.php(.+?)" class="tabBody">(.+?)<\/a><\/td>/is',$buffer,$matches);
$newseite = $url . "/home/structure/control.php" . $matches[3];
$buffer = "";
$fp = fsockopen ("www.wetter.com", 80, $errno, $errstr, 30);
fputs ($fp, "GET $newseite HTTP/1.0\r\nHost: Search\r\n\r\n");
while (!feof($fp)) $buffer .= fgets ($fp, 1024);
fclose ($fp);
}
preg_match('/alt="Webcam für (.+?) \(Deutschland\) zeigen"/is',$buffer,$matches);
$stadt = $matches[1];
preg_match('/<td width="66"><span class="tabHeadline">Temp.:<\/span><\/td>(.+?)<td width="53" align="right"><span class="tabBody">(.+?)<\/span><\/td>(.+?)<td width="30" align="right"><span class="tabBody">&C<\/span><\/td>/is',$buffer,$matches);
$akt_temp = $matches[2];
preg_match('/<table width="200"(.+?)<td><span class="tabHeadline">max. Temp.:<\/span><\/td>(.+?)<td align="center" colspan="2"><span class="tabBody">(.+?) &C<\/span><\/td>/is', $buffer, $matches);
$max_temp = $matches[3];
preg_match('/<table width="200"(.+?)<td><span class="tabHeadline">min. Temp:<\/span><\/td>(.+?)<td align="center" colspan="2"><span class="tabBody">(.+?) &C<\/span><\/td>/is', $buffer, $matches);
$min_temp = $matches[3];
preg_match('/<table width="200"(.+?)<td><span class="tabHeadline">Niederschlag\?<\/span><\/td>(.+?)<td align="center" colspan="2"><span class="tabBody">(.+?) %<\/span><\/td>/is', $buffer, $matches);
$niederschlag = $matches[3];
if (empty($stadt)) {
$return["error"] = 1;
$return["msg"] = "wetter infos: kein ergebnis gefunden!";
return $return;
} else {
$return["error"] = 0;
$return["plz"] = $params;
$return["stadt"] = $stadt;
$return["akt_temp"] = $akt_temp;
$return["max_temp"] = $max_temp;
$return["min_temp"] = $min_temp;
$return["niederschlag"] = $niederschlag;
return $return;
}
}
} else {
$return["error"] = 1;
$return["msg"] = "Please try again later!";
return $return;
}
}
?>