Zend - The PHP Company




Weather

Add Code


Current Weather  

Type: code fragment
Added by: greedo
Entered: 18/05/2000
Last modified: 08/12/1999
Rating: *** (7 votes)
Views: 23165
Grabs the current weather based on your IP from weather.com. Some basic error handling has been added. A default zip code has been added so zip codes that can not be calculated can be over written


<?
    $defZipCode 
"49341";

    
$IP getenv("REMOTE_ADDR");
    
exec("whois -h whois.arin.net $IP",$arZipCode);        

    if(
strstr(substr($arZipCode[2],-5),"-")) {
        
$zipCode intval(substr($arZipCode[2],strlen($arZipCode[2]) - 105));
    } else {
        
$zipCode intval(substr($arZipCode[2],-5));
    }

    if(
strlen($zipCode) < 5) { $zipCode $defZipCode; }

    
$url "http://www.weather.com/weather/us/zips/$zipCode.html";

    
$string implode("n"file($url));
    
$string2 explode("<!-- obs include -->"$string);
    
$string3 explode("<!-- forecast include -->"$string2[1]);
    
$string5 explode("<CENTER>"$string3[0]);

    
$string4 explode("<!-- end of obs/fcst table -->"$string3[1]);

    
$currentweather $string5[0];
    
    
$extforecast $string4[0];

    echo 
$currentweather;
    echo 
$extforecast;
?>



Usage Example


See the example


Rate This Script





Search



This Category All Categories