Get actual weather information



by Administrator author list

<?php

function getWeatherRSS($weatherLink){
   
   if (
$fp fopen($weatherLink'r')) {
      
$content '';
        
      while (
$line fread($fp1024)) {
         
$content .= $line;
      }
   }

   return 
$content;  
}

function 
processWeather($wurl){
    
    
$wrss getWeatherRSS($wurl);
    
$temp  '-';
    
$tempu '';
    
$city  '';
    
    if (
strlen($wrss)>100){
        
// Get temperature unit C or F
        
$spos strpos($wrss,'yweather:units temperature="')
              + 
strlen('yweather:units temperature="');
        
$epos strpos($wrss,'"',$spos);
        if (
$epos>$spos){
            
$tempu substr($wrss,$spos,$epos-$spos);
        } 

        
$spos strpos($wrss,'yweather:wind chill="')
              + 
strlen('yweather:wind chill="');
        
$epos strpos($wrss,'"',$spos);
        if (
$epos>$spos){
            
$temp += substr($wrss,$spos,$epos-$spos);
        } else {
            
$temp '-';
        }
        
        
// Get city name
        
$spos strpos($wrss,'yweather:location city="')
              + 
strlen('yweather:location city="');
        
$epos strpos($wrss,'"',$spos);
        if (
$epos>$spos){
            
$city substr($wrss,$spos,$epos-$spos);
        } 

    }
    
    return 
$city.' &nbsp;'.$temp.' &deg;'.$tempu;
    
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>Micro Weather</title>
   <link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="main">
      <div id="caption">CURRENT WEATHER</div>
      <div id="icon2">&nbsp;</div>
      <div id="result"><?php echo processWeather('http://xml.weather.yahoo.com/forecastrss?p=USTX0327&u=c'); ?>
      </div>
      <div id="source">Micro Weather 1.0</div>
    </div>
</body>   



article index
page 1 : untitled page
page 2 - current : Complete code


Tags: weather

Php Toys - 2006 - Php resources, scripts and tutorials - Privacy Policy
Insurance Index - Tutorial collection - Forex trading, brokers, reviews - Mortgage payment calculator
{THEMEDISCLAIMER}
Render time: 0.1243 sec, 0.0157 of that for queries. DB queries: 25.