Więc pozostało mi napisanie go samemu.
Klasa zaciąga dane z kanału RSS strony www.wunderground.com oraz przedstawia dane w postaci przejrzystej tablicy.
Oto przykład zastosowania:
<?php require_once( 'Weather.class.php' ); $objWeather = new Weather( 'http://www.wunderground.com/auto/rss_full/global/ stations/12495.xml' ); // pogoda dla Lublina $objWeather2 = new Weather( 'http://www.wunderground.com/auto/rss_full/global/stations/12495.xml', false ); ?>
Wynik:
Cytat
Array
(
[temperature] => 4°C
[humidity] => 78%
[pressure] => 1013hPa
[conditions] =>
[winddirection] => NE
[windspeed] => 11km/h
[updated] => 23:00 28.03.2005
)
Array
(
[temperature] => 39°F
[humidity] => 78%
[pressure] => 29.93in
[conditions] =>
[winddirection] => NE
[windspeed] => 7mph
[updated] => 23:00 28.03.2005
)
(
[temperature] => 4°C
[humidity] => 78%
[pressure] => 1013hPa
[conditions] =>
[winddirection] => NE
[windspeed] => 11km/h
[updated] => 23:00 28.03.2005
)
Array
(
[temperature] => 39°F
[humidity] => 78%
[pressure] => 29.93in
[conditions] =>
[winddirection] => NE
[windspeed] => 7mph
[updated] => 23:00 28.03.2005
)
I wreszcie kod klasy:
<?php class Weather { private $strFilePath = ''; private $strContent = ''; private $blnMetricUnits = true; /** * Konstruktor klasy * * @param string $strFilePath Plik kanału RSS z http://wunderground.com z pogodą dla danego miasta * @param boolean $blnMetricUnits System metryczny: true - \"nasz\", false - brytyjski * @return void */ public function Weather( $strFilePath, $blnMetricUnits = true ) { $this->strFilePath = $strFilePath; $this->blnMetricUnits = $blnMetricUnits; $objSimpleXMLElement = simplexml_load_file( $this->strFilePath ); $arrElements = $objSimpleXMLElement->xpath( '//channel/item/description' ); $this->strContent = ( string )$arrElements[ 0 ]; $this->ExplodeContent(); $this->CreateContent(); } /** * Wstępna obróbka informacji z kanału RSS */ private function ExplodeContent() { foreach( $arrContent as $strValue ) { $this->arrContent[ strtolower( str_replace( ' ', '', $arrTemp[ 0 ] ) ) ] = iconv( \"UTF-8\", \"ISO-8859-2\", $arrTemp[ 1 ] ); } } /** * Wydobycie z kanału RSS informacji o pogodzie i utworzenie tablicy zawier jące te informacje */ private function CreateContent() { foreach( $this->arrContent as $strKey => $strValue ) { { $intIndex = ( $this->blnMetricUnits ) ? 1 : 0; } else { } } } /** * Metoda zwracająca dane o pogodzie * * @return array */ public function GetConditions() { return $this->arrConditions; } } ?>
Proszę o sugestie i uwagi
