PHP NOAA 5 Day Forecast - Problem With 'Down Arrow" Graphic

Hi all,

Been using Carterlake’s PHP NOAA 5 Day Forecast Script for months with no problems. However, with winter here, there is a problem for days when the forecast is for falling temperatures. The regular graphic for the day appears, but an additional graphic is called for a ‘down arrow’ and I get a “red x” instead of that graphic. I have the down arrow graphic on my system.

Looking at the source code for the actual web page, it looks like this:


<b>Today
</b>
<img src="/forecast/images/sn50.jpg" width="55" height="58" alt="Chance Snow. Chance for Measurable Precipitation 50%" title="Chance Snow. Chance for Measurable Precipitation 50%\" >
Chance
Snow
Hi <font color="#FF0000">41&deg;F</font><img src="images/down.gif" border="0" alt="Falling Temperatures"></td>

If you look closely, the normal graphic is called like this:


<img src="/forecast/images/sn50.jpg" 

But, for the down arrow, it is called like this:


<img src="images/down.gif"

How do I set up the directory structure on my webserver to get this graphic in the right location, because apparently it cant go into the normal location for the other graphics. I even created a new images directory and then placed the down arrow into that directory, but that is not working. I think the lack of that leading “/” before the word “images” is freakin it out.

Thanks!

The Up or Down arrow is actually after the Hi/Low temperature reading in the html from NOAA…

I have a modified carterlake advforecast that handles that (assuming images are in the /forecast/images directory)

<?php 
/*------------------------------------------------
//
//This is a more advanced version of the forecast script
//It uses file caching and feed failure to better handle when NOAA is down
//
// modified by Ken True - Saratoga-weather.org -- 15-Jan-2007 or XHTML 1.0-Strict
//
//import NOAA Forecast info 
//data ends up in three different arrays: 
//$forecasticons[x]  x = 0 thru 9   This is the icon and text around it 
//$forecasttemp[x] x= 0 thru 9    This is forecast temperature with styling
//$forecasttitles[x]  x = 0 thru 12   This is the title word for the time period 
//$forecasttext[x]  x = 0 thru 12  This is the detail text for the forecast 
// 
//$forecastupdate  This is the time of last update
//$forecastcity    This is the city name for the forecast
//$forecastoffice  This is the NWS Office providing the forecast
//
//Also, in order for this to work correctly, you need the NOAA icons (or make your own... 
//there are over 200!). These need to be placed in the path where the original NOAA icons
//are located. In my case, they are at: \forecast\images\
//properly (so make a folder in your web HTML root called "forecast", then make a folder in it 
//called "images", and place the icons in this folder)
//
//http://members.cox.net/carterlakeweather/forecasticons.zip (380K)
//
//URL below --MUST BE-- the Printable Point Forecast from the NOAA website
//
//Not every area of the US has a printable point forecast
//
//This script will ONLY WORK with a printable point forecast!
// 
//To find yours in your area: 
// 
//Go to www.noaa.gov 
//Click on the Storm Watch map (middle lower left of page) 
//Click on your state 
//Click on  your area of the state 
//Scroll down to the "Additional Forecasts & Info" 
//Click on Printable Forecast 
//------------------------------------------------*/

// Get the forecast.txt file or a new one from NOAA 
// You have to have a forecast.txt in place for this script to work
// You can see ours at http://www.carterlake.org/forecast.txt

// This is version 1.1 with Ken's modifications from Saratoga Weather
// http://saratoga-weather.org/

// You can now force the cache to update by adding ?force=1 to the end of the URL

if ( empty($_REQUEST['force']) ) 
        $_REQUEST['force']="0";

$Force = $_REQUEST['force'];

$cacheName = "forecast.txt"; 
$fileName = "http://www.srh.noaa.gov/forecast/MapClick.php?CityName=Gulf+Shores&state=AL&site=MOB&TextType=2";

// The number 1800 below is the number of seconds the cache will be used instead of pulling a new file
// 1800 = 60s x 30m so it retreives every 30 minutes. 

if ($Force==1) {
      $html = fetchUrlWithoutHanging($fileName,$cacheName); 
      $fp = fopen($cacheName, "w"); 
      $write = fputs($fp, $html); 
      fclose($fp);  } 

if (filemtime($cacheName) + 1800 > time()) { 
      $html = implode('', file($cacheName)); 
    } else { 
      $html = fetchUrlWithoutHanging($fileName,$cacheName); 
      $fp = fopen($cacheName, "w"); 
      $write = fputs($fp, $html); 
      fclose($fp);  } 

      // Just get the top of the NWS page for editing 

      preg_match('|<tr valign ="top" align="center">(.*)<table width="670"|s', $html, $betweenspan); 
      $forecastop  = $betweenspan[1]; 

      // Chop up each icon html and place in array 
      preg_match_all("/<td.*>(.*)<\/td>/Uis", $forecastop, $headers); 
      $forecasticons = $headers[1]; 
	  

// saratoga-weather.org mod: fix up html for XHTML 1.0-Strict
     $Status = "<!-- \n" . print_r($forecasticons,true) . "-->\n";
		for ($i=0;$i<=8;$i++) {
		   $forecasticons[$i] = preg_replace('|/forecast/images|Uis',
		   './forecast/images',$forecasticons[$i]);
		   $forecasticons[$i] = preg_replace('|

\s+$|is',
		    "",$forecasticons[$i]);
//		   $forecasticons[$i] = preg_replace('|temperatures|is','temps',$forecasticons[$i]);
//		   $forecasticons[$i] = preg_replace('|Falling|is',' Falling',$forecasticons[$i]);
		   $forecasticons[$i] = preg_replace('|\'|is','"',$forecasticons[$i]);  // change all ' to "
		   $forecasticons[$i] = preg_replace('|\\\\" >
|is','" />
',$forecasticons[$i]);
		   $forecasticons[$i] = preg_replace('|<font color="(.*)\">(.*)</font>|Uis',
		     "<span style=\"color: $1;\">$2</span>",$forecasticons[$i]);
		   preg_match_all('|
([^<]+)(<span.*</span>.*)|is',$forecasticons[$i],$matches);
//		   $Status .= "<!-- matches\n ".print_r($matches,true). "-->\n";
           if(preg_match('|<img .*>|i',$matches[2][0])) {
		     $t = $matches[2][0];
			 $t = preg_replace('|<img src="([^"]+)" (border="0") alt="([^"]+)">|i',
			  "<img src=\"./forecast/\\1\" style=\"border: none;\" alt=\"\\3\" title=\"\\3\" />",$t);
			 $matches[2][0] = $t;
		   }
		   $forecasttemp[$i] = $matches[1][0] . $matches[2][0]; // just the temp line
		   // remove the temp from the forecasticons
		   $forecasticons[$i] = preg_replace('|'.$matches[0][0].'|is','',$forecasticons[$i]);
		   // fix up the 
 to be 
 for XHTML compatibility
		   $forecasticons[$i] = preg_replace('|
|Uis','
',$forecasticons[$i]);
//		   $forecasttemp[$i] = preg_replace('|
|Uis','
',$forecasttemp[$i]);
//		   $forecasttemp[$i] = trim($forecasttemp[$i]);
		}

          $Status .= "<!-- \n" . print_r($forecasticons,true) . "-->\n";

// end saratoga-weather.org XHTML 1.0-Strict mod

      // Now get just the bottom of the NWS page for editing 
      preg_match('|</table>(.*)<hr>|s', $html, $betweenspan); 
      $forecast  = $betweenspan[1]; 

      // Chop up each title text and place in array 
      preg_match_all('|<b>(.*): </b>|Ui', $forecast, $headers); 
      $forecasttitles = $headers[1]; 

      // Chop up each forecast text and place in array 
      preg_match_all('|</b>(.*)
|Ui', $forecast, $headers); 
      $forecasttext = $headers[1]; 

      // Grab the Last Update date and time. 
      preg_match('|Last Update: (.*)|', $html, $betweenspan); 
      $forecastupdated  = $betweenspan[1]; 
	  $forecastupdated  = preg_replace('|<[^>]+>|Uis','',$forecastupdated); // remove html markup
	  

// saratoga-weather.org mod: 
	  // Grab the NWS Forecast for (city name)
	  preg_match('|<b>NWS Forecast for: (.*)</b>|',$html,$betweenspan);
	  $forecastcity  = $betweenspan[1];

	  // Grab the Issued by office
	  preg_match('|Issued by: (.*)
|',$html,$betweenspan);
	  $forecastoffice  = $betweenspan[1];

  if (isset($doPrintNWS) && ! $doPrintNWS ) {
      return;
  }
  if (isset($_REQUEST['inc']) && 
      strtolower($_REQUEST['inc']) == 'noprint' ) {
	  return;
  }
// end saratoga-weather.org mod

function fetchUrlWithoutHanging($url,$cacheurl)
   {
   // Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed
   $numberOfSeconds=4;    

   // Suppress error reporting so Web site visitors are unaware if the feed fails
   error_reporting(0);

   // Extract resource path and domain from URL ready for fsockopen

   $url = str_replace("http://","",$url);
   $urlComponents = explode("/",$url);
   $domain = $urlComponents[0];
   $resourcePath = str_replace($domain,"",$url);

   // Establish a connection
   $socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds);

   if (!$socketConnection)
       {

       $html = implode('', file($cacheurl));
       return($html);

       // You may wish to remove the following debugging line on a live Web site
       // print("<!-- Network error: $errstr ($errno) -->");
       }    // end if
   else    {
       $xml = '';
       fputs($socketConnection, "GET $resourcePath HTTP/1.0\r\nHost: $domain\r\n\r\n");
   
       // Loop until end of file
       while (!feof($socketConnection))
           {
           $xml .= fgets($socketConnection, 4096);
           }    // end while

       fclose ($socketConnection);

       }    // end else

   return($xml);

   }    // end function


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>NWS Forecast for <?php echo $forecastcity; ?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; background-color:#FFFFFF">

<?php
print $Status;
// if the forecast text is blank, prompt the visitor to force an update

if (strlen($forecasttext[0])<2) {

echo '

Forecast blank? <a href="' . $PHP_SELF . '?force=1">Force Update</a>

';

} ?>
  <table width="670" style="border: none;">
    <tr align="center" style="background-color: #FFFFFF;">
      <td><b>National Weather Service Forecast for: </b><span style="color: green;">
	   <?php echo $forecastcity; ?></span>

        Issued by: <?php echo $forecastoffice; ?>
      </td>
    </tr>
    <tr>
      <td align="center">Updated: <?php echo $forecastupdated; ?>
	  </td>
    </tr>
    <tr>
      <td align="center">&nbsp;
	    <table width="100%" border="0" cellpadding="0" cellspacing="0">  
	      <tr valign ="top" align="center">
	<?php
	  for ($i=0;$i<=8;$i++) {
	    print "<td style=\"width: 11%;\"><span style=\"font-size: 8pt;\">$forecasticons[$i]</span></td>\n";
	  }
	?>
          </tr>	
          <tr valign ="top" align="center">
	  <?php
	  for ($i=0;$i<=8;$i++) {
	    print "<td style=\"width: 11%;\">$forecasttemp[$i]</td>\n";
	  }
	  ?>
          </tr>
        </table>
     </td>
   </tr>
</table>
  <p>&nbsp;</p>

<table style="border: 0" width="670">
	<?php
	  for ($i=0;$i<=13;$i++) {
        print "<tr valign =\"top\" align=\"left\">\n";
	    print "<td style=\"width: 20%;\"><b>$forecasttitles[$i]</b>
&nbsp;
</td>\n";
	    print "<td style=\"width: 80%;\">$forecasttext[$i]</td>\n";
		print "</tr>\n";
	  }
	?>
   </table>

<p>&nbsp;</p>
<p>Forecast from <a href="<?php echo htmlspecialchars($fileName); ?>">NOAA-NWS</a> for <?php echo $forecastcity; ?>.</p>
</body>
</html>

I’d done this as part of the website design for Zeke’s Gulf Shores WX site and had seen the same issue as you did.

Best regards,
Ken

I had the same issue and placed the image file “down.gif” in the directory to which the path was pointing to (<img src=“images/down.gif”)