Weather
|
|
|
|
<?php class Weather {
var $Sunrise, $Sunset, $RAWXML, $LUpdated, $Obst, $City, $State, $Condition, $Barometer, $BarometerStatus, $Wind, $Gust, $Direction, $Humidity, $Visibility, $UVIndex, $UVStatus, $Dewpoint, $IconNum;
function Weather($zip) { $xmi=join('',file("http://xoap.weather.com/weather/local/".$zip."?cc=*&prod=xoap&par=1003188692&key=7392ac66b4e27671")); $this->RAWXML = $xmi; $this->Sunrise = $this->in("<sunr>","</sunr>",$xmi); $this->Sunset = $this->in("<suns>","</suns>",$xmi); $this->LUpdated=$this->in("<lsup>","</lsup>",$xmi); $this->Obst = $this->in("<obst>","</obst>",$xmi);
$dnaminfo = $this->in("<dnam>","</dnam>",$xmi);
if(eregi("(.*), (.*) ((.*))", $dnaminfo, $m)) { $this->City = $m[1]; $this->State = $m[2];
} $this->Condition=$this->in("<t>","</t>",$xmi); $this->Temperature=$this->in("<tmp>","</tmp>",$xmi); $barinfo = $this->in("<bar>","</bar>",$xmi); $this->Barometer=$this->in("<r>","</r>",$barinfo); $this->BarometerStatus=$this->in("<d>","</d>",$barinfo);
$windinfo = $this->in("<wind>","</wind>",$xmi); $this->Wind = $this->in("<s>","</s>",$windinfo);
$this->Gust = $this->in("<gust>","</gust>",$windinfo);
$this->Direction = $this->in("<t>","</t>",$windinfo); $this->Humidity = $this->in("<hmid>","</hmid>",$xmi)."%"; $this->Visibility = $this->in("<vis>","</vis>",$xmi); $uvinfo = $this->in("<uv>","</uv>",$xmi); $this->UVIndex = $this->in("<i>","</i>",$uvinfo); $this->UVStatus = $this->in("<t>","</t>",$uvinfo); $this->Dewpoint = $this->in("<dewp>","</dewp>",$xmi); $this->Icon = "http://image.weather.com/web/common/wxicons/52/".$this->in("<icon>","</icon>", $xmi).".gif";
}
function in($One,$Two,$Three) { $Reg = $One."(.*)".$Two;
if(eregi($Reg,$Three,$m)) {
return $m[1];
} else {
return "N/A";
}
}
}
//How to use: $weather = new Weather("21211"); //Weather variables:
//$weather->RAWXML Raw XML data
//$weather->Sunrise Sunrise
//$weather->Sunset Sunset
//$weather->LUpdated Last Updated
//$weather->Obst Where it is reported from
//$weather->City City of Zipcode
//$weather->State State of Zipcode
//$weather->Condition Condition (Fair or Partly Cloudy)
//$weather->Temperature Temperature outside
//$weather->Barometer The barometer (29.87)
//$weather->BarometerStatus The barometer stat (Falling, Steady or Rising)
//$weather->Wind The current wind in MPH
//$weather->Gust The current wind gust. N/A if no gust.
//$weather->Direction The direction of the wind.
//$weather->Humidity The Humidity outside (96%)
//$weather->Visibility The visibility outside (4.0)
//$weather->UVIndex UV Index (1)
//$weather->UVStatus UV Index Status (Minimal)
//$weather->Dewpoint The dewpoint (36)
//$weather->Icon The Icon Number for the Condition (52)
?>
|
|
|
Usage Example
|
$weather = new Weather("21211");
echo "Baltimore Temperature: ";
echo $weather->Temperature;
|
|
|
Rate This Script
|
|
|
|