Version: 5.1
Type: Sample Code (HOWTO)
Category: HTTP
License: GNU General Public License
Description: this little script in a class will show you everything on the weather including Barometer and text forecasts splitting n so you can replace n with <BR>. borrowed some of the code from a site and really changed to make it so it was from scratch
<?php //////////////////////////////////// // VERSION: 5.1 // BY: lentin64 // CHANGES: Gets from wunderground, // weather.net, and yahoo! weather // Changed: Dec 19, 2002 // DESCRIPTION: Read changes. // Now doesn't get from weather.com anymore // // City, State coming soon, stick with // the ZIP CODE thingy for now ///////////////////////////////////// if($idalert != "") { $rr=join('',file("http://www.weather.com/weather/alerts/?alertId=".$idalert)) or die("Could not open file!"); if(eregi('<TD CLASS="blkVerdanaText11">(.*)</TD>',$rr,$m)) { $m[1]=str_replace("Close this window","",$m[1]); echo "<A HREF='javascript:history.back()'>Back</A><BR>".$m[1]."<BR><A HREF='javascript:history.back(1)'>Back</A>"; exit; } else { echo "Could not get Advisory #".$idalert."!"; exit; } } if($zip != "") { echo "<FORM ACTION='$PHP_SELF' ACTION=get>"; echo "Zip Code: <INPUT TYPE=text NAME=zip MAXLENGTH=5><BR>"; echo "<INPUT TYPE=submit VALUE='Get Weather'>"; exit; } $cp=file("http://www.wunderground.com/auto/raw/".$zip); $data=explode("|",join('',$cp)); echo "<font size=5>Current Conditions for ".$data[18].", ".$data[19].":</font><BR>"; echo "<table><tr><td>Currently ".$data[8]."</td><td width=37%>The Temperature is now ".$data[1]." F</td></tr></table><BR>"; $weathercom=join('',file("http://www.weather.com/weather/local/".$zip)); if(eregi("var marqueecontents="(.*)</font>"",$weathercom,$m)) { $m[1]=str_replace("/weather/alerts/?alertId=",$PHP_SELF."?zip=".$zip."&idalert=",$m[1]); $m[1]=str_replace(" ","<BR>",$m[1]); $m[1]=str_replace(" [More Details]","",$m[1]); echo "Advisory(s):<BR>"; echo "<SCRIPT> document.write("".$m[1].""); </SCRIPT>"; } echo "<TABLE>n"; if($data[2] != "N/A") { echo "<TR><TD>Wind Chill</TD><TD width=50%>".$data[2]."F</TD></TR>n"; } if($data[3] != "N/A") { echo "<TR><TD>Heat Index</TD><TD width=50%>".$data[3]."F</TD></TR>n"; } echo "<TR><TD>Humidity</TD><TD width=50%>".$data[4]."</TD></TR>n"; echo "<TR><TD>Dew Point</TD><TD width=50%>".$data[5]."</TD></TR>n"; echo "<TR><TD>Wind</TD><TD width=50%>From the ".$data[6]." MPH</TD></TR>n"; echo "<TR><TD>Barometer</TD><TD width=50%>".$data[7]."</TD></TR>n"; echo "<TR><TD>Visibility</TD><TD width=50%>".$data[9]." Miles (1=bad, 10=good)</TD></TR>n"; echo "<TR><TD>Sunrise</TD><TD width=50%>".$data[10]."</td></tr>n"; echo "<TR><TD>Sun Set</TD><TD width=50%>".$data[11]."</td></tr>n"; echo "</table><BR><BR>"; echo "<FONT size=5>Radar</FONT><BR>"; if($po == "animate") { echo "<TABLE><TR><TD><IMG SRC='"; echo "http://www.insolation.weather.net/cgi-bin/interradziprain?zipcode"; echo "=".$zip."&height=270&width=360' width=360 height=270>"; echo "</TD><TD width=50%><A HREF='?zip=".$zip."&po=static'>Static Radar</A></td></tr></table>"; } else { echo "<TABLE><TR><TD><IMG SRC='"; echo "http://www.insolation.weather.net/cgi-"; echo "bin/interradzipstaticrain?zipcode=".$zip; echo "&height=270&width=360' WIDTH=360 height=270></TD>"; echo "<TD width=50%><A HREF='?zip=".$zip."&po=animate'>Animated Radar</A></td></tr></table>"; } echo "<BR><BR>"; echo "<font size=5>Forecast</font><BR>"; $ch=join('',file("http://search.weather.yahoo.com/search/weather2?p=".$zip)); if(eregi("<!----------------------- FORECAST ------------------------->(.*)<!--ENDFC-->",$ch,$mm)) { $detailed=$mm[1]; $detailed=str_replace('<td width="17%" align=center><font face=Arial size=2><b>6-10 Day</b></font></td>','',$detailed); $detailed=str_replace('<a href="http://rd.yahoo.com/M=216468.1953735.3440073.1888545/D=wt/S=20078731:WTHE/A=1056905/R=0/*http://www.weather.com/weather/extended/USMD0423?par=yahoo&site=www.yahoo.com&promo=forecast">Extended Forecast at weather.com</a>','',$detailed); echo $detailed."<BR><BR>"; } if(eregi("<!--TEXT FORECAST-->(.*)<!--ENDTEXT FORECAST-->",$ch,$mm)){ echo $mm[1]; } ?>