I've seen a few people writing weather ripping scripts and I've been obsessed with the weather as of late so here is a weather ripping script for weather.gov. I disclaim everything, use at your own risk. 😉
<?php
if($subbed == 1){
$subbed = 0;
$url_string = file_get_contents("http://www.crh.noaa.gov/zipcity.php?theme=default&user=default&forecast=zandh&inputstring=" . $inputstring);
// gets the city and state
$zip_pos_one = strpos($url_string, "<td background=\"/weather/images/fcicons/forecast_blank.jpg\" height=\"57\" class=\"white1\">");
$zip_pos_two = strpos($url_string, "<a href=\"#contents\"><img src=\"/weather/images/fcicons/skipgraphic.gif\" alt=\"Skip to Detailed 7-Day Forecast\" width=\"1\" height=\"1\" border=\"0\">");
$city_state = strip_tags(substr($url_string, $zip_pos_one, ($zip_pos_two - $zip_pos_one)));
// check for hazardous weather
if(substr_count($url_string, "Hazardous weather condition(s):") > 0){
$startString = "<span class=\"warn\">";
$endString = "</span>";
/*i hate pcre because i suck, my lack of pcre skills makes my expression get duplicates...
strip out the duplicates from the array and put them into an ordered list.
*/
preg_match_all("|$startString(.*)$endString|U", $url_string, $matches);
$hazard_array = array_unique($matches);
$hazards = "<tr><td colspan=\"2\" align=\"center\"><p>Hazardous weather condition(s):<br><ul>";
for($x = 0; $x < count($hazard_array); $x++){
$hazards .= "<li>" . $hazard_array[$x][0] . "</li>";
}
$hazards .= "</ul></p></td></tr>";
}
// get all of the current weather data
// i'm sure there is a better way to do all of this but this works.
$data_pos_one = strpos($url_string, "Last Update on ");
$data_pos_two = strpos($url_string, "obslocal.php?warnzone=");
// replaces <br> with [br] and </td> with [btd] to keep track of the data after the tags are stripped
$btd_string = strip_tags(str_replace("<br>", "[br]", str_replace("</td>", "[btd]", (substr($url_string, $data_pos_one, ($data_pos_two - $data_pos_one)) . ">"))));
$data_array = explode("[btd]", $btd_string);
$cond_temp = explode("[br][br]", $data_array[1]);
$output = "<div align=\"center\"><table border=\"1\">";
$output .= "<tr><td colspan=\"2\" align=\"center\"><b>" . $city_state ."</b> (<b>" . $inputstring . "</b>)<br>" . str_replace("[br]", "", $data_array[0]) . "</td></tr>";
$output .= "<tr><td rowspan=\"6\" align=\"center\"><p>" . $cond_temp[0] . "<br>" . str_replace("[br]", " ", $cond_temp[1]) . "</p></td><td>" . $data_array[2] . $data_array[3] . "</td></tr>";
$output .= "<tr><td>" . $data_array[4] . $data_array[5] . "</td></tr>";
$output .= "<tr><td>" . $data_array[6] . $data_array[7] . "</td></tr>";
$output .= "<tr><td>" . $data_array[8] . $data_array[9] . "</td></tr>";
$output .= "<tr><td>" . $data_array[10] . $data_array[11] . "</td></tr>";
$output .= "<tr><td>" . $data_array[12] . $data_array[13] . "</td></tr>";
$output .= $hazards;
$output .= "<tr><td colspan=\"2\" align=\"center\"><a target=\"_new\" href=\"http://www.crh.noaa.gov/zipcity.php?inputstring=" . $inputstring . "\">National Weather Service Forecast</a></td></tr></table><font size=\"2\">Data ripped from the <a href=\"http://www.weather.gov/\">National Weather Service</a>.</font></div>";
echo $output;
}
?>
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>weather.gov</title>
</head>
<body>
<center>
<form method="post" action="<?php echo $PHP_SELF; ?>">
<input type="input" name="inputstring">
<input type="hidden" name="subbed" value="1">
<input type="submit" name="submit" value="submit">
</form>
</center>
</body>
</html>