PX : code

Wunderground Weather by phpcoder
Download this code


Code:

<?php
if(!function_exists("file_get_contents")) {
function 
file_get_contents($url) {
$fp fopen($url"r");
$read fread($fpfilesize($url));
fclose($fp);
return 
$read;
}
}

$input "Baltimore, Maryland"//or you can just put a zip code there
$wground file_get_contents("http://www.wunderground.com/cgi-bin/findweather/getForecast?brand=raw&query=".$input);

if(
ereg("^<br>"$wground)) {
echo 
"<B>Error</B> Bad city, state or zip code";
} else {
echo 
"Last updated at ".$wground[0];
echo 
"Temp: ".$wground[1]."&deg;F.";
if(
$wground[2] != "N/A") {
echo 
"<br>Wind chill: ".$wground[2];
}
if(
$wground[3] != "N/A") {
echo 
"<br>Heat index: ".$wground[3];
}
echo 
"<br>Humidity: ".$wground[4]."<br>";
echo 
"Dew point: ".$wground[5]."<br>";
echo 
"Wind: ".$wground[6]." MPH<br>";
echo 
"Pressure/Barometer: ".$wground[7]." inches<br>";
echo 
"Skies: ".$wground[8]."<br>";
echo 
"Visibility: ".$wground[9]." Miles<br>";
echo 
"Sunrise/Sunset: ".$wground[10]."/".$wground[11]."<br><br>";
echo 
"This report was from ".$wground[18].", ".$wground[19].".";
}
?>

This code was only an example of what you can do with this script.
You can use it for anything, even make a big weather website with it.

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.