Weather Extraction Snippet

 
Post new topic   Reply to topic    PHP User Group Malta Forum Index // Links to PHP Good Tutorials
View previous topic :: View next topic  
Author Message
yancho
Site Admin


Joined: 13 Nov 2007
Posts: 51
Location: Iklin

PostPosted: Sat Feb 09, 2008 11:55 am    Post subject: Weather Extraction Snippet Reply with quote

 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&#176;F / 2.8&#176;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 Smile


_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
yancho
Site Admin


Joined: 13 Nov 2007
Posts: 51
Location: Iklin

PostPosted: Mon Feb 11, 2008 12:42 pm    Post subject: Reply with quote

 Edited the preg_match :

php:

preg_match_all
('/- (-?[0-9\.].+?)F \/ (-?[0-9\.].+?)C \| ([a-zA-Z ]+?) -/ '$title$match) ;



This will capture negative temperatures Smile


_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
Post new topic   Reply to topic    PHP User Group Malta Forum Index // Links to PHP Good Tutorials All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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

alexisRed v1.2 // Theme Created By: Andrew Charron and Web Hosting Bluebook // Icons in Part By: Travis Carden
Boards optimised using the phpBB-SEO mod found at phpbb-seo.com
Boards hosted courtesy of solutions-lab.net
Link Backs : PHPClasses.org - MT Page :: PHPUsergroups.org - MT Page



Powered by phpBB © 2001, 2002 phpBB Group