Services_Weather
[ class tree: Services_Weather ] [ index: Services_Weather ] [ all elements ]

Source for file metar-extensive.php

Documentation is available at metar-extensive.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
  3.  
  4. /**
  5.  * Elaborate example for the METAR/TAF-service
  6.  *
  7.  * Well, this is a more elaborate example how to create a neat little page
  8.  * with fetching METAR/TAF data from NOAA and putting it into a design.
  9.  * I'm not too proud of my design-skills, most of the stuff here is taken
  10.  * from the metar-block which can be found within the Horde Framework,
  11.  * courtesy of Rick Emery - creative pixelshoving isn't my domain :-P
  12.  * I've used a Firefox for checking the design, so don't be too
  13.  * disappointed, if the page looks shabby with the IE, not that I care
  14.  * very much anyway ;-)
  15.  * Have fun!
  16.  * 
  17.  * PHP versions 4 and 5
  18.  *
  19.  * <LICENSE>
  20.  * Copyright (c) 2005-2011, Alexander Wirtz
  21.  * All rights reserved.
  22.  * 
  23.  * Redistribution and use in source and binary forms, with or without
  24.  * modification, are permitted provided that the following conditions
  25.  * are met:
  26.  * o Redistributions of source code must retain the above copyright notice,
  27.  *   this list of conditions and the following disclaimer.
  28.  * o Redistributions in binary form must reproduce the above copyright notice,
  29.  *   this list of conditions and the following disclaimer in the documentation
  30.  *   and/or other materials provided with the distribution.
  31.  * o Neither the name of the software nor the names of its contributors
  32.  *   may be used to endorse or promote products derived from this software
  33.  *   without specific prior written permission.
  34.  * 
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  37.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  38.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  39.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  40.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  41.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  42.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  43.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  44.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  45.  * POSSIBILITY OF SUCH DAMAGE.
  46.  * </LICENSE>
  47.  * 
  48.  * @category    Web Services
  49.  * @package     Services_Weather
  50.  * @author      Alexander Wirtz <eru@php.net>
  51.  * @copyright   2005-2011 Alexander Wirtz
  52.  * @license     http://www.opensource.org/licenses/bsd-license.php  BSD License
  53.  * @version     SVN: $Id$
  54.  * @link        http://pear.php.net/package/Services_Weather
  55.  * @filesource
  56.  */
  57.  
  58. //-------------------------------------------------------------------------
  59. // This is the area, where you can customize the script
  60. //-------------------------------------------------------------------------
  61. $location        "Bonn, Germany"// The city we want to fetch the data for.
  62.                                     // Where the search function will look for
  63.                                     // the ICAO database (generated with the
  64.                                     // buildMetarDB.php script)
  65. $dsn             "sqlite://localhost//usr/local/lib/php/data/Services_Weather/servicesWeatherDB"
  66. $sourceMetar     "http";          // This script will pull the METAR data via http
  67. $sourceTaf       "http";          //                           TAF
  68. $sourcePathMetar "";              // Only needed when non-standard access is used
  69. $sourcePathTaf   "";              //
  70. $cacheType       "";              // Set a type (file, db, mdb, ...) to
  71.                                     // enable caching.
  72. $cacheOpt        = array();         // Cache needs various options, depending
  73.                                     // on the container-type - please consult
  74.                                     // the Cache manual / sourcecode!
  75. $unitsFormat     "metric";        // The format the units are displayed in -
  76.                                     // metric, standard or some customization.
  77. $dateFormat      "j. M Y";        // Set the format the date is displayed in
  78. $timeFormat      "H:i";           //                    time
  79. //-------------------------------------------------------------------------
  80.  
  81. // Load the Weather class
  82. require_once "Services/Weather.php";
  83.  
  84. // Object initialization - error checking is important, because of
  85. // handling exceptions such as missing PEAR modules
  86. $metar &Services_Weather::service("Metar");
  87. if (Services_Weather::isError($metar)) {
  88.     die("Error: ".$metar->getMessage()."\n");
  89. }
  90.  
  91. // Set parameters for DB access, needed for location searches
  92. $metar->setMetarDB($dsn);
  93. if (Services_Weather::isError($metar)) {
  94.     echo "Error: ".$metar->getMessage()."\n";
  95. }
  96.  
  97. // Initialize caching
  98. if (strlen($cacheType)) {
  99.     $status $metar->setCache($cacheType$cacheOpt);
  100.     if (Services_Weather::isError($status)) {
  101.         echo "Error: ".$status->getMessage()."\n";
  102.     }
  103. }
  104.  
  105. // Define the units format, bring the retrieved format into
  106. // something more common...
  107. $metar->setUnitsFormat($unitsFormat);
  108. $units $metar->getUnitsFormat();
  109. $units["temp"]   "&deg;".strtoupper($units["temp"]);
  110. $units["wind"]   "&nbsp;".str_replace("kmh""km/h"$units["wind"]);
  111. $units["vis"]    "&nbsp;".$units["vis"];
  112. $units["height""&nbsp;".$units["height"];
  113. $units["pres"]   "&nbsp;".$units["pres"];
  114. $units["rain"]   "&nbsp;".$units["rain"];
  115.  
  116. $metar->setMetarSource($sourceMetar$sourcePathMetar$sourceTaf$sourcePathTaf);
  117.  
  118. // Set date-/time-format
  119. $metar->setDateTimeFormat($dateFormat$timeFormat);
  120.  
  121. // Search for defined location and fetch the first item found.
  122. // Bail out if something bad happens...
  123. $search $metar->searchLocation($locationtrue);
  124. if (Services_Weather::isError($search)) {
  125.     die("Error: ".$search->getMessage()."\n");
  126. }
  127.  
  128. // Retrieve data, store in variables, bail out on error
  129. $fetch = array(
  130.     "location" => "getLocation",
  131.     "weather"  => "getWeather",
  132.     "forecast" => "getForecast"
  133. );
  134. foreach ($fetch as $variable => $function{
  135.     $$variable $metar->$function($search);
  136.     if (Services_Weather::isError($$variable)) {
  137.         echo "Error: ".$$variable->getMessage()."\n";
  138.         continue;
  139.     }
  140. }
  141.  
  142. // Now we output all the data, please don't expect extensive comments here, this is basic
  143. // HTML/CSS stuff. Also this isn't a very fancy design, it's just to show you, what
  144. // the script is able to do (and more ;-))...
  145. ?>
  146. <html>
  147. <head>
  148.     <title>Services_Weather::METAR/TAF</title>
  149.     <style type="text/css">
  150.         .normal     { font-family: Arial, Helvetica, sans-serif; font-size: 11pt; font-weight: normal; font-style: normal }
  151.         .italic     { font-weight: normal; font-style: italic }
  152.         .bold       { font-weight: bold; font-style: normal }
  153.         .bolditalic { font-weight: bold; font-style: italic }
  154.         .redbold    { font-weight: bold; font-style: normal; color: #ff0000 }
  155.         .bluebold   { font-weight: bold; font-style: normal; color: #0000ff }
  156.         .bggrey     { background-color: #e9e9e9 }
  157.         .bgkhaki    { background-color: #d8d8c0 }
  158.         .reg        { font-size: 7pt; vertical-align: super }
  159.         img         { vertical-align: middle; border-style: none; border-width: 0px }
  160.         a           { font-weight: bold; font-style: italic; color: #993300; text-decoration: none }
  161.         a:visited   { font-weight: bold; font-style: italic; color: #993300; text-decoration: none }
  162.         a:hover     { font-weight: bold; font-style: italic; color: #cc3300; text-decoration: underline }
  163.         table       { border: 0px none black; border-spacing: 0px }
  164.         td          { font-family: Arial, Helvetica, sans-serif; font-size: 11pt; font-weight: normal; font-style: normal }
  165.     </style>
  166. </head>
  167. <body class="normal">
  168. <?php
  169. // Debug outputs the raw data fetched by the foreach-loop above, just for checking...
  170. if (isset($_GET["debug"])) {
  171.     echo "<pre>\n";
  172.     var_dump($location$weather$forecast);
  173.     echo "</pre>\n";
  174. ?>
  175. <span class="bluebold" style="font-size: 13pt">Weather Forecast</span> created with <a style="font-size: 13pt" href="http://pear.php.net/">PEARs</a> <a style="font-size: 13pt" href="http://pear.php.net/package/Services_Weather/">Services_Weather</a><br>
  176. <table style="width: 100%">
  177. <tr>
  178.     <td>
  179.         <table border="0" style="border-top: 2px solid #524b98; border-bottom: 2px solid #e0e3ce; border-left: 2px solid #b8b6c1; border-right: 2px solid #8b87a0; width: 100%">
  180.         <tr class="bgkhaki">
  181.             <td colspan="4" style="border-bottom: 2px solid #abada2"><span class="bold"><?=$location["name"]?> (<?=$search?>)</span></td>
  182.         </tr>
  183.         <tr>
  184.             <td><span class="bold">Sunrise:</span> <img style="width: 28px; height: 13px; vertical-align: baseline" alt="Sunrise" src="images/sunrise.gif"> <?=$location["sunrise"]?></td>
  185.             <td><span class="bold">Sunset:</span> <img style="width: 30px; height: 15px; vertical-align: baseline" alt="Sunset" src="images/sunset.gif"> <?=$location["sunset"]?></td>
  186.             <td style="width: 190px">&nbsp;</td>
  187.             <td style="width: auto">&nbsp;</td>
  188.         </tr>
  189.         <tr style="height: 15px">
  190.             <td nowrap><span class="bold">Temperature:</span> <?=round($weather["temperature"]1).$units["temp"]?></td>
  191.             <td nowrap><span class="bold">Dew point:</span> <?=round($weather["dewPoint"]1).$units["temp"]?></td>
  192.             <td nowrap><span class="bold">Felt temperature:</span> <?=round($weather["feltTemperature"]1).$units["temp"]?></td>
  193.             <td rowspan="4" valign="top">
  194.                 <span class="bold">Trend:</span><br>
  195. <?php
  196. if (isset($weather["trend"]&& sizeof($weather["trend"])) {
  197.     // Output the trends, loop through the arrays,
  198.     // convert the stuff to nice looking design, jadda, jadda...
  199.     foreach ($weather["trend"as $trend{
  200.         foreach ($trend as $key => $val{
  201.             switch ($key{
  202.                 case "type":
  203.                     switch ($val{
  204.                         case "NOSIG":
  205.                             $string "No Significant Weather";
  206.                             break;
  207.                         case "TEMPO":
  208.                             $string "Temporary Weather";
  209.                             break;
  210.                         case "BECMG":
  211.                             $string "Weather Becoming";
  212.                             break;
  213.                     }
  214.                     $value  "";
  215.                     foreach (array("from""to""at"as $time{
  216.                         if (isset($trend[$time])) {
  217.                             $value .= " ".$time." ".$trend[$time];
  218.                         }
  219.                     }
  220.                     ($value != ""$value  trim($value).":":"";
  221.                     $string '<span class="italic">'.$string.'</span>';
  222.                     $value  '<span class="italic">'.$value.'</span>';
  223.                     break;
  224.                 case "wind":
  225.                     $string "Wind:";
  226.                     $value  (strtolower($trend["windDirection"]== "calm""Calm" "From the ".$trend["windDirection"]." (".$trend["windDegrees"]."&deg;) at ".round($trend["wind"]1).$units["wind"];
  227.                     if (isset($trend["windVariability"])) {
  228.                         $value .= ", variable from ".$trend["windVariability"]["from"]."&deg; to ".$trend["windVariability"]["to"]."&deg;";
  229.                     }
  230.                     if (isset($trend["windGust"])) {
  231.                         $value .= ", with gusts up to ".round($trend["windGust"]1).$units["wind"];
  232.                     }
  233.                     break;
  234.                 case "visibility":
  235.                     $string "Visibility:";
  236.                     $value  strtolower($trend["visQualifier"])." ".round($trend["visibility"]1).$units["vis"];
  237.                     break;
  238.                 case "clouds":
  239.                     $string "Clouds:";
  240.                     $value  "";
  241.                     for ($i = 0; $i sizeof($val)$i++{
  242.                         $cloud ucwords($val[$i]["amount"]);
  243.                         if (isset($val[$i]["type"])) {
  244.                             $cloud .= " ".$val[$i]["type"];
  245.                         }
  246.                         if (isset($val[$i]["height"])) {
  247.                             $cloud .= " at ".$val[$i]["height"].$units["height"];
  248.                         }
  249.                         $value .= $cloud." ";
  250.                     }
  251.                     break;
  252.                 case "condition":
  253.                     $string "Condition:";
  254.                     $value  ucwords($val);
  255.                     break;
  256.                 case "pressure":
  257.                     $string "Pressure:";
  258.                     $value  round($val1).$units["pres"];
  259.                     break;
  260.                 case "from":
  261.                 case "to":
  262.                 case "at":
  263.                 case "windDirection":
  264.                 case "windDegrees":
  265.                 case "windVariability":
  266.                 case "windGust":
  267.                 case "visQualifier":
  268.                     continue 2;
  269.                 default:
  270.                     $string ""$value "";
  271.                     var_dump($key$val);
  272.                     break;
  273.             }
  274. ?>
  275.                 <?=$string?> <?=$value?><br>
  276. <?php
  277.         }
  278.  
  279.     }
  280. else {
  281. ?>
  282.                 none<br>
  283. <?php
  284. }
  285. ?>
  286.                 <span class="bold">Remarks:</span><br>
  287. <?php
  288. if (isset($weather["remark"]&& sizeof($weather["remark"])) {
  289.     // Same for the remarks, even less spectacular...
  290.     foreach($weather["remark"as $key => $val{
  291.         switch ($key{
  292.             case "autostation":
  293.             case "presschg":
  294.             case "nospeci":
  295.             case "sunduration":
  296.             case "maintain":
  297.                 $string "";
  298.                 $value  $val;
  299.                 break;
  300.             case "seapressure":
  301.                 $string "Pressure at sealevel:";
  302.                 $value  round($val1).$units["pres"];
  303.                 break;
  304.             case "1htemp":
  305.                 $string "Temperature for last hour:";
  306.                 $value  round($val1).$units["temp"];
  307.                 break;
  308.             case "1hdew":
  309.                 $string "Dew Point for last hour:";
  310.                 $value  round($val1).$units["temp"];
  311.                 break;
  312.             case "6hmaxtemp":
  313.             case "6hmintemp":
  314.                 if (!isset($weather["remark"]["6hmaxtemp"]&& !isset($weather["remark"]["6hmintemp"])) {
  315.                     continue(2);
  316.                 }
  317.                 $string "Max/Min Temp for last 6 hours:";
  318.                 $value  (isset($weather["remark"]["6hmaxtemp"])) round($weather["remark"]["6hmaxtemp"]1).$units["temp""-";
  319.                 $value .= "/";
  320.                 $value .= (isset($weather["remark"]["6hmintemp"])) round($weather["remark"]["6hmintemp"]1).$units["temp""-";
  321.                 unset($weather["remark"]["6hmaxtemp"]); unset($weather["remark"]["6hmintemp"]);
  322.                 break;
  323.             case "24hmaxtemp":
  324.             case "24hmintemp":
  325.                 if (!isset($weather["remark"]["24hmaxtemp"]&& !isset($weather["remark"]["24hmintemp"])) {
  326.                     continue(2);
  327.                 }
  328.                 $string "Max/Min Temp for last 24 hours:";
  329.                 $value  (isset($weather["remark"]["24hmaxtemp"])) round($weather["remark"]["24hmaxtemp"]1).$units["temp""-";
  330.                 $value .= "/";
  331.                 $value .= (isset($weather["remark"]["24hmintemp"])) round($weather["remark"]["24hmintemp"]1).$units["temp""-";
  332.                 unset($weather["remark"]["24hmaxtemp"]); unset($weather["remark"]["24hmintemp"]);
  333.                 break;
  334.             case "snowdepth":
  335.                 $string "Snow depth:";
  336.                 $value  $val.$units["rain"];
  337.                 break;
  338.             case "snowequiv":
  339.                 $string "Water equivalent of snow:";
  340.                 $value  $val.$units["rain"];
  341.                 break;
  342.             case "sensors":
  343.                 $string "";
  344.                 $value  implode("<br>"$val);
  345.                 break;
  346.             default:
  347.                 $string ""$value "";
  348.                 var_dump($key$val);
  349.                 break;
  350.         }
  351. ?>
  352.                 <?=$string?> <?=$value?><br>
  353. <?php
  354.     }
  355. else {
  356. ?>
  357.                 none<br>
  358. <?php
  359. }
  360. ?>
  361.             </td>
  362.         </tr>
  363.         <tr style="height: 15px">
  364.             <td colspan="2" style="width: 310px" nowrap><span class="bold">Pressure:</span> <?=round($weather["pressure"]1).$units["pres"]?></td>
  365.             <td nowrap><span class="bold">Humidity:</span> <?=round($weather["humidity"]2)?>%</td>
  366.         </tr>
  367.         <tr style="height: 15px">
  368.             <td colspan="2" nowrap>
  369.                 <span class="bold">Wind:</span> <?=strtolower($weather["windDirection"]== "calm" "Calm" "From the ".$weather["windDirection"]." (".$weather["windDegrees"]."&deg;) at ".round($weather["wind"]1).$units["wind"]?> 
  370.                 <?=isset($weather["windVariability"]"<br>variable from ".$weather["windVariability"]["from"]."&deg; to ".$weather["windVariability"]["to"]."&deg;" ""?> 
  371.                 <?=isset($weather["windGust"]"<br>with gusts up to ".round($weather["windGust"]1).$units["wind"""?> 
  372.             </td>
  373.             <td valign="top" nowrap><span class="bold">Visibility:</span> <?=strtolower($weather["visQualifier"])?> <?=round($weather["visibility"]1).$units["vis"]?></td>
  374.         </tr>
  375.         <tr>
  376.             <td><span class="bold">Current condition:</span><br><?=isset($weather["condition"]ucwords($weather["condition"]"No Significant Weather"?></td>
  377.             <td><img style="height: 32px; width: 32px" alt="<?=isset($weather["condition"]ucwords($weather["condition"]"No Significant Weather"?>" src="images/32x32/<?=$weather["conditionIcon"]?>.png"></td>
  378. <?php
  379. if (isset($weather["precipitation"]&& sizeof($weather["precipitation"])) {
  380.     // Output a line for each type of precipitation,
  381.     // distinguish between string and numeric values
  382. ?>
  383.                 <br><span class="bold">Precipitation:</span><br>
  384. <?php
  385.     for ($i = 0; $i sizeof($weather["precipitation"])$i++{
  386.         $precip "last ".$weather["precipitation"][$i]["hours"]."h: ".$weather["precipitation"][$i]["amount"];
  387.         $precip .= (ctype_alpha($weather["precipitation"][$i]["amount"])) "" $units["rain"];
  388. ?>
  389.                 <?=$precip?><br>
  390. <?php
  391.     }
  392. }
  393. ?>
  394.             </td>
  395.             <td valign="top">
  396.                 <span class="bold">Clouds:</span><br>
  397. <?php
  398. if (isset($weather["clouds"]&& sizeof($weather["clouds"])) {
  399.     // Yeah, clouds... same as in the trend handling...
  400.     for ($i = 0; $i sizeof($weather["clouds"])$i++{
  401.         $cloud ucwords($weather["clouds"][$i]["amount"]);
  402.         if (isset($weather["clouds"][$i]["type"])) {
  403.             $cloud .= " ".$weather["clouds"][$i]["type"];
  404.         }
  405.         if (isset($weather["clouds"][$i]["height"])) {
  406.             $cloud .= " at ".$weather["clouds"][$i]["height"].$units["height"];
  407.         }
  408. ?>
  409.                 <?=$cloud?><br>
  410. <?php
  411.     }
  412. else {
  413. ?>
  414.                 Clear Below <?=$metar->convertDistance(12000"ft"$units["height"]).$units["height"]?> 
  415. <?php
  416. }
  417. ?>
  418.             </td>
  419.         </tr>
  420.         </table>
  421.     </td>
  422. </tr>
  423. <tr>
  424.     <td>
  425.         <table style="border-top: 2px solid #524b98; border-bottom: 2px solid #e0e3ce; border-left: 2px solid #b8b6c1; border-right: 2px solid #8b87a0; width: 100%">
  426.         <tr class="bgkhaki">
  427.             <td colspan="3" align="center" style="border-bottom: 2px solid #abada2"><span class="bold">Forecast (TAF)</span><br>valid from <span class="bold"><?=$forecast["validFrom"]?></span> to <span class="bold"><?=$forecast["validTo"]?></span></td>
  428.         </tr>
  429.         <tr valign="top">
  430.             <td colspan="3">
  431.                 <table style="width: 100%">
  432.                 <tr>
  433.                     <td align="center" class="bgkhaki" style="height: 15px; border-top: 2px solid #d8d8c0; border-right: 2px solid #8b87a0; border-left: 2px solid #d8d8c0">&nbsp;</td>
  434.                     <td align="center" style="width: 18%"><span class="bold">Meteorological Conditions</span></td>
  435.                     <td align="center" style="width: 18%" class="bggrey"><span class="bold">Wind</span></td>
  436.                     <td align="center" style="width: 18%"><span class="bold">Visibility</span></td>
  437.                     <td align="center" style="width: 18%" class="bggrey"><span class="bold">Clouds</span></td>
  438.                     <td align="center" style="width: 18%"><span class="bold">Condition</span></td>
  439.                 </tr>
  440. <?php
  441. $times array_keys($forecast["time"]);
  442. $pre   = array("wind" => 0"vis" => 0"clouds" => 0"cond" => 0);
  443. // Ok, the forecast is a bit more interesting, as I'm taking a few
  444. // precautions here so that the table isn't filled up to the max.
  445. // o If a value is repeated in the next major timeslot (not when
  446. //   significant weather changes are processed), it's not printed
  447. // o Significant weather gets its own rows, with times printed normal
  448. //   as in opposition to bold print for major timeslots
  449. // o The while($row)-construct below is for handling the significant
  450. //   weather, as I point $row to $row["fmc"] afterwards, where the
  451. //   smaller changes are mentioned
  452. for ($i = 0; $i sizeof($forecast["time"])$i++{
  453.     $row $forecast["time"][$times[$i]];
  454.  
  455.     // Create timestamp
  456.     $start $times[$i];
  457.     if ($i + 1 < sizeof($forecast["time"])) {
  458.         $end $times[$i + 1];
  459.     else {
  460.         $end substr($forecast["validRaw"]-2).":00";
  461.         $end ($end == "24:00""00:00" $end;
  462.     }
  463.     $time    $start." - ".$end;
  464.     $class   ' class="bold"';
  465.     // This is for outputting "Becoming", "Temporary" and such
  466.     $fmc     = isset($row["fmc"]$row["fmc": false; 
  467.     $fmctype "";
  468.     $fmccnt  = 0;
  469.  
  470.     while ($row{
  471. ?>
  472.                 <tr class="bgkhaki">
  473.                     <td style="height: 1px; empty-cells: show; border-right: 2px solid #8b87a0; border-left: 2px solid #d8d8c0"></td>
  474.                     <td style="height: 1px" colspan="5"></td>
  475.                 </tr>
  476.                 <tr>
  477.                     <td align="center" class="bgkhaki" style="border-right: 2px solid #8b87a0; border-left: 2px solid #d8d8c0" nowrap><span<?=$class?>><?=$time?></span></td>
  478.                     <td align="center"><?=$fmctype?></td>
  479. <?php
  480.         // This loops through the available data and processes it
  481.         // for output, the different methods were already used above
  482.         // (Only difference is the checking for the pre-values.)
  483.         foreach(array("wind""vis""clouds""cond"as $val{
  484.             switch ($val{
  485.                 case "wind":
  486.                     if (!isset($row["windDirection"])) {
  487.                         $string "&nbsp;";
  488.                     else {
  489.                         $string strtolower($row["windDirection"]== "calm" "Calm" "From the ".$row["windDirection"]." (".$row["windDegrees"]."&deg;)<br>at ".round($row["wind"]1).$units["wind"];
  490.                         if (isset($row["windProb"])) {
  491.                             $string .= " (".$row["windProb"]."%&nbsp;Prob.)";
  492.                         }
  493.                         if ($string === $pre["wind"]{
  494.                             $string "&nbsp;";
  495.                         else {
  496.                             $pre["wind"$string;
  497.                         }
  498.                     }
  499.                     $class ' class="bggrey"';
  500.                     break;
  501.                 case "vis":
  502.                     if (!isset($row["visibility"])) {
  503.                         $string "&nbsp;";
  504.                     else {
  505.                         $string strtolower($row["visQualifier"])." ".round($row["visibility"]1).$units["vis"];
  506.                         if (isset($row["visProb"])) {
  507.                             $string .= " (".$row["visProb"]."%&nbsp;Prob.)";
  508.                         }
  509.                         if ($string === $pre["vis"]{
  510.                             $string "&nbsp;";
  511.                         else {
  512.                             $pre["vis"$string;
  513.                         }
  514.                     }
  515.                     $class '';
  516.                     break;
  517.                 case "clouds":
  518.                     if (!isset($row["clouds"])) {
  519.                         $string "&nbsp;";
  520.                     else 
  521.                         $clouds  "";
  522.                         for ($j = 0; $j sizeof($row["clouds"])$j++{
  523.                             $cloud ucwords($row["clouds"][$j]["amount"]);
  524.                             if (isset($row["clouds"][$j]["type"])) {
  525.                                 $cloud .= " ".$row["clouds"][$j]["type"];
  526.                             }
  527.                             if (isset($row["clouds"][$j]["height"])) {
  528.                                 $cloud .= " at ".$row["clouds"][$j]["height"].$units["height"];
  529.                             }
  530.                             if (isset($row["clouds"][$j]["prob"])) {
  531.                                 $cloud .= " (".$row["clouds"][$j]["prob"]."%&nbsp;Prob.)";
  532.                             }
  533.                             $clouds .= $cloud."<br>";
  534.                         }
  535.                         if ($clouds === $pre["clouds"]{
  536.                             $string "&nbsp;";
  537.                         else {
  538.                             $string        $clouds;
  539.                             $pre["clouds"$clouds;
  540.                         }
  541.                     }
  542.                     $class ' class="bggrey"';
  543.                     break;
  544.                 case "cond":
  545.                     if (!isset($row["condition"]|| (isset($prerow&& $prerow["condition"== $row["condition"])) {
  546.                         $string "&nbsp;";
  547.                     else {
  548.                         $string ucwords($row["condition"]);
  549.                     }
  550.                     $class '';
  551.             }
  552. ?>
  553.                     <td valign="top"<?=$class?>><?=$string?></td>
  554. <?php
  555.         }
  556. ?>                    
  557.                 </tr>
  558. <?php
  559.         // Now check for significant weather changes and move
  560.         // the row accordingly... maybe ugly coding, but this
  561.         // is for showing design, not for fany programming ;-)
  562.         if ($fmc && $fmccnt sizeof($fmc)) {
  563.             $row     $fmc[$fmccnt];
  564.             $fmccnt++;
  565.             $fmctype $row["type"];
  566.             // Check if we have a timestamp, don't output if it's
  567.             // the same as the major-timeslot
  568.             if (!isset($row["from"]|| $row["from"]." - ".$row["to"== $time{
  569.                 $time "&nbsp;";
  570.             else {
  571.                 $time    $row["from"]." - ".$row["to"];
  572.             }
  573.             switch ($row["type"]{
  574.                 case "PROB":
  575.                     $fmctype "";
  576.                     break;
  577.                 case "TEMPO":
  578.                     $fmctype "Temporary";
  579.                     break;
  580.                 case "BECMG":
  581.                     $fmctype "Becoming";
  582.                     break;
  583.             }
  584.             if (isset($row["probability"])) {
  585.                 $fmctype .= " (".$row["probability"]."%&nbsp;Prob.)";
  586.             }
  587.         else {
  588.             $row = false;
  589.         }
  590.     }
  591. }
  592. ?>                
  593.                 <tr>
  594.                     <td class="bgkhaki" style="height: 1px; empty-cells: show; border-bottom: 2px solid #d8d8c0; border-left: 2px solid #d8d8c0; border-right: 2px solid #8b87a0"></td>
  595.                     <td style="height: 1px" colspan="5"></td>
  596.                 </tr>
  597.                 </table>
  598.             </td>
  599.         </tr>
  600.         <tr class="bgkhaki">
  601.             <td style="width: 93px; border-top: 2px solid #abada2">&nbsp;</td>
  602.             <td style="border-top: 2px solid #abada2">Updated: (<?=substr($weather["update"]-5)?>&nbsp;/&nbsp;<?=substr($forecast["update"]-5)?>)</td>
  603.             <td style="border-top: 2px solid #abada2" align="right">All times UTC</td>
  604.         </tr>
  605.         </table>
  606.     </td>
  607. </tr>
  608. </table>
  609. <a href="javascript:history.back()">back</a>
  610. </body>
  611. </html>

Documentation generated on Mon, 11 Mar 2019 15:50:58 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.