Weather.php

<html>
<head>
   <title>TAOS WEATHER</title>
   <!-- <meta http-equiv="Refresh" content="1200"> -->
   <style type="text/css">
      <!--
      body
         {
         border: solid black 3px;
         background-color:#efedde;
         color:#000099;
         }
      -->
   </style>
   <script type="text/javascript" language="JavaScript">
      setInterval
         ("document.body.innerHTML='<pre>content expired</pre>';" +
          "location.href='http://mjyonline.com/Demos/Weather.php'",
         1200000);
   </script>
</head>
<body>
<?php
   
echo "<pre>";
   
$dateString strtoupper (date ('l F d h:iA'));
   echo 
"<a href='http://weather.noaa.gov/weather/current/KSKX.html'>TAOS WEATHER</a>: $dateString\n";

   
// display current weather conditions:
   
$theURL="http://weather.noaa.gov/weather/current/KSKX.html";
   if (!(
$contents file_get_contents ($theURL)))
      {
      echo 
"COULD NOT OPEN $theURL</pre></body></html>";
      exit;
      }
   
$contents strip_tags ($contents);
   
// temperature:
   
$pattern 'Temperature[[:space:]]+([[:print:]]+)';
   if (
ereg ($pattern$contents$result))
      {
      echo 
"TEMPERATURE: $result[1]\n";
      }
   else
      {
      echo 
"CAN'T FIND TEMPERATURE.\n";
      };
   
// sky conditions:
   
$pattern 'Sky conditions[[:space:]]+([[:print:]]+)';
   if (
ereg ($pattern$contents$result))
      {
      echo 
"SKY CONDITIONS: ".strtoupper ($result[1])."\n";
      }
   else
      {
      echo 
"CAN'T FIND SKY CONDITIONS.\n";
      };
   
// wind:
   
$pattern 'Wind[[:space:]]+([[:print:]]+)';
   if (
ereg ($pattern$contents$result))
      {
      
$windStr strtoupper ($result[1]);
      if (
strlen ($windStr) > 54)
         {
         
$pos strrpos (substr ($windStr055), " ");
         
$windStr substr_replace ($windStr"\n      "$pos1);
         }
      echo 
"WIND: ".$windStr."\n\n";
      }
   else
      {
      echo 
"CAN'T FIND SKY CONDITIONS.\n\n";
      };

   
// display forecast:
   
echo "<a href='http://weather.noaa.gov/cgi-bin/iwszone?Sites=:nmz004'>7 DAY FORECAST</a>:\n";
   
$theURL="http://weather.noaa.gov/cgi-bin/iwszone?Sites=:nmz004";
   if (!(
$fileArray file ($theURL)))
      {
      echo 
'COULD NOT OPEN URL.</body></html>';
      exit;
      }
   
$count1 0;
   
$count2 0;
   foreach (
$fileArray as $row)
      {
      
$pattern '   FCST     ';
      if (
ereg ($pattern$row))
         {
         
$count1 2;
         continue;
         }
      if (
$count1 0)
         {
         echo 
rtrim (substr ($row3))."\n";
         --
$count1;
         if (
$count1 == 0)
            echo 
"------   ------   ------   ------   ------   ------   ------\n";
         }
      
$pattern '^TAOS[[:space:]]$';
      if (
ereg ($pattern$row))
         {
         
$count2 3;
         continue;
         }
      if (
$count2 0)
         {
         if (
$count2 1)
            echo 
rtrim (substr ($row3))."\n";
         else
            echo 
rtrim (substr ($row4))."\n";
         --
$count2;
         }
      }
   echo 
'</pre>';
?>
</body>
</html>