Current Weather
Eastern Time


CURRENTLY
$len) $str = substr($str,0,$len); return str_pad($str,$len," ",STR_PAD_BOTH); } function connectToURL($addr, $port, $path, $user="", $pass="", $timeout="30") { $urlHandle = fsockopen($addr, $port, $errno, $errstr, $timeout); if ($urlHandle) { socket_set_timeout($urlHandle, $timeout); if ($path) { #$urlString = "GET $path HTTP/1.0\r\nHost: $addr\r\nConnection: Keep-Alive\r\nUser-Agent: Mozilla/5.001 (windows; U; NT4.0; en-us) Gecko/25250101\r\n"; $urlString = "GET $path HTTP/1.0\r\nHost: $addr\r\nConnection: Keep-Alive\r\nUser-Agent: myURLGrabber\r\n"; if ($user) $urlString .= "Authorization: Basic ".base64_encode("$user:$pass")."\r\n"; $urlString .= "\r\n"; fputs($urlHandle, $urlString); $response = fgets($urlHandle,1024); if (substr_count($response, "200 OK") > 0) // Check the status of the link { $endHeader = false; // Strip initial header information while ( !$endHeader) { if (fgets($urlHandle,1024) == "\r\n") $endHeader = true; } return $urlHandle; // All OK, return the file handle } else if (strlen($response) < 15) // Cope with wierd non standard responses { fclose($urlHandle); return -1; } else // Cope with a standard error response { fclose($urlHandle); return substr($response,9,3); } } return $urlHandle; } else return 0; } function get_weather() { global $weather, $zipcode; /* possible vars (with examples): current weather temp=71 uv=3 humid=59 dew=56 wind=12 cond=cloud_partly pollen=5.5 forecast today/tonight temph1=75 templ1=52 fcond1=thunder_isolated_tstorm forecast tomorrow temph2=67 templ2=46 fcond2=clear_sunny forecast next day temph3=71 templ3=50 fcond3=clear_sunny */ $file = fopen ("http://www.w3.weather.com/weather/local/$zipcode", "r"); #$file = connectToURL("www.w3.weather.com", 80, "/weather/local/$zipcode", "", "", 2); if (!$file) { echo "Error getting weather\n"; return false; } else { while (!feof ($file)) { $line = fgets ($file, 1024); if (substr($line,0,9) == "OAS_query") { $line = str_replace("'", "", $line); $line = str_replace(";", "", $line); $line = str_replace("\n", "", $line); parse_str($line,$weather); break; } } fclose($file); // translate conditions $weather['cond'] = translate_condition($weather['cond']); // not sunny at night if (date("G") >= 18 and strstr($weather['cond'], "Sunny")) $weather['cond'] = "Clear"; $weather['fcond1'] = translate_condition($weather['fcond1']); // not sunny at night if (date("G") >= 14 and strstr($weather['fcond1'], "Sunny")) $weather['fcond1'] = "Clear"; $weather['fcond2'] = translate_condition($weather['fcond2']); $weather['fcond3'] = translate_condition($weather['fcond3']); //echo $weather['fcond3']."\n"; return true; } return false; } function translate_condition($cond) { $cond = strtolower($cond); if ($cond == "thunder") return "T-Storms"; elseif ($cond == "thunder_isolated_tstorm") return "Isol T-Storms"; elseif ($cond == "thunder_strong_tstorm") return "Heavy T-Storms"; elseif ($cond == "thunder_scat_tstorm") return "Scat T-Storms"; elseif ($cond == "cloud_mostly") return "Mostly Cloudy"; elseif ($cond == "cloud_partly") return "Partly Cloudy"; elseif ($cond == "cloud") return "Cloudy"; elseif ($cond == "cloud_haze") return "Hazy"; elseif ($cond == "clear_sunny") return "Sunny"; elseif ($cond == "clear_mostly") return "Mostly Clear"; elseif ($cond == "clear_mostly_sunny") return "Mostly Sunny"; elseif ($cond == "snow") return "Snow"; elseif ($cond == "snow_showers") return "Light Snow"; elseif ($cond == "rain") return "Light Rain"; elseif ($cond == "rain_showers") return "Showers"; elseif ($cond == "rain_scat_showers") return "Few Showers"; elseif ($cond == "rain_and_snow") return "Rain/Snow"; else return $cond; } ?>