| View previous topic :: View next topic |
yancho Site Admin
Joined: 13 Nov 2007 Posts: 56 Location: Iklin
|
Posted: Sat Feb 09, 2008 11:55 am Post subject: Weather Extraction Snippet |
|
|
|
Below find an extraction script you mind find useful from a website that provides RSS feed of Weather Conditions around the World
I used this script for some USA zips, hence the URL path .. this if or Malta :
http://rss.wunderground.com/auto/rss_full/global/stations/16597.xml?units=both
16597 is Malta, you can get the RSS feed you need from : http://www.wunderground.com/global/ML.html
( full list : http://www.wunderground.com/global/Region/EU/Temperature.html )
| php: |
echo "<br><br> Current Conditions in : <b>" . $zip ."</b> are : ";
$zip = str_replace (" ", "_", $zip);
$url = "http://rss.wunderground.com/auto/rss_full/NC/".$zip.".xml?units=both";
$xml = simplexml_load_file($url);
$title = $xml->channel->item[0]->title;
//echo $title;
$wind = $xml->channel->item[0]->description;
//echo $wind;
//<title>Current Conditions - 37.0F / 2.8C | Clear - 5:32 AM EST Feb. 8</title>
preg_match_all('/- ([0-9\.].+?)F \/ ([0-9\.].+?)C \| ([a-zA-Z ]+?) -/ ', $title, $match) ;
//print_r ($match);
echo $match[1][0]." Farenheight -=- ".$match[2][0]." Celcius ::: Weather Conditions are : ".$match[3][0];
//<description><![CDATA[Temperature: 37.0°F / 2.8°C | Humidity: 72% | Pressure: 29.69in / 1005.3hPa (Steady) | Conditions: Clear | Wind Direction: NNW | Wind Speed: 0.0mph / 0.0km/h<img src="http://server.as5000.com/AS5000/adserver/image?ID=WUND-00049&C=0" width="0" height="0" border="0"/>]]></description>
$st = strstr($wind, 'Wind Direction: ');
list($windspd,$null) = explode('|',$st);
//echo $windspd;
list($null,$winds) = explode( ': ',$windspd);
//print_r ($windspd);
echo " -=- Wind Direction : ".$winds;
|
This is the output :
| Quote: |
Current Conditions in : ANGIER are : 63.7 Farenheight -=- 17.6 Celcius ::: Weather Conditions are : Clear -=- Wind Direction : NE
|
Hope you find this script useful
_________________
 |
|
| Back to top |
|
|
yancho Site Admin
Joined: 13 Nov 2007 Posts: 56 Location: Iklin
|
Posted: Mon Feb 11, 2008 12:42 pm Post subject: |
|
|
|
Edited the preg_match :
| php: |
preg_match_all('/- (-?[0-9\.].+?)F \/ (-?[0-9\.].+?)C \| ([a-zA-Z ]+?) -/ ', $title, $match) ;
|
This will capture negative temperatures
_________________
 |
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
Powered by phpBB © 2001, 2002 phpBB Group |
|
|