advforecast2.php script minor change...

I discovered I’d left out a ‘:’ in one expression, so a return to point-printable from failover zone forecast wouldn’t happen if the text of the forecast contained the word ‘location’.


	  if (preg_match('/Temporary|Location/Uis',$html)) {


	  if (preg_match('/Temporary|Location:/Uis',$html)) {

or download the fixed version from

Best regards,

btw… this version supports the /images/wtf rewrite to /forecast/images directory too.

Thanks Ken…I made note of it, and will update mine soon…Have a Good Memorial Day Weekend,…Chris

Hello All: I have been using the forecast page for some time. Today, for some reason, the forecase page was not displaying…just the link to force the page to update. When you clicked on the force update there was no change. When I saw this post I decided to correct the code.

I copied the script from the link above and made the necessary changes for my area. Once changes were complete I uploaded the php file to the same location as before. When I call up my page the PHP code is displayed. I’m not quite sure what I did wrong…

This is what I’m using to call the script into my forecast page:

<?php $doIncludeNWS = true; include("advforecast2.php"); ?>

Link to my forecast page:

Thanks in advance for any assistance…Ronnie

I just put the code in a file like this:

Then call it as:

<? include "" ?>

and the result is:


Bob’s got the right idea.

Copy the code from and save it as advforecast2.php on your local copy of your website.

Edit your copy of advforecast2.php and change the $NOAAzone and $filename variables to have the settings for your area.

Save the edited advforecast2.php and upload it as advforecast2.php to your website.

Edit your wxlocal2.html in your \wdisplay\webfiles directory and insert

$doIncludeNWS = true;
include("advforecast2.php"); ?>

where you’d like the forecast to appear on your wx2.php page.

Save the wxlocal2.html and let WD upload it as wx2.php.

That should fix it.

Bob… you can do the same thing you suggested, but I’d recommend you change the URL to be

<? include "" ?>

to have advforecast2.php omit the unneeded … and from the output (don’t want to confuse older browsers :slight_smile: ).

Best regards,

this is all I entered for my forecast page:

<div id="main-copy"> 
<?php $doIncludeNWS = true; include("advforecast2.php"); ?>

<!-- ##### Footer ##### -->

It will center the forecast with Icons page, and also add dark background…Most like it centered on their page, but not all add the dark background’s your choice.

Thanks for the assistance…I’ve got the page working correctly. I’m unsure what I did wrong but it’s working…



This is the point printable forecast I am using in the script:

$fileName = '';

My forecast is there, I can put that URL in a browser and it comes up. When I open my web page, the script does not use that forecast, and I can’t figure out why. It isn’t a cache issue, because I replaced the cache with a blank page and it still did not not use the forecast I have listed. It wouldn’t matter so much, but I saw today that it is screwed up.

Ahh… that fix to change

	  if (preg_match('/Temporary|Location/Uis',$html)) {


	  if (preg_match('/Temporary|Location:/Uis',$html)) {

actually appears twice in the code. Don’t forget to change the second one too around

if (filemtime($cacheName) + 1800 > time()) { 
      $html = implode('', file($cacheName)); 
    } else { 
      $html = fetchUrlWithoutHanging($fileName,$cacheName); 
	  if (preg_match('/Temporary|Location:/Uis',$html)) {
	     $usingFile = "(Zone forecast)";
         $html = fetchUrlWithoutHanging($backupfileName,$cacheName); 
      $fp = fopen($cacheName, "w"); 
      $write = fputs($fp, $html); 
      fclose($fp);  } 

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

I tried that with a copy of your script and it works fine for New Holland, PA (instead of the Lancaster Country zone forecast).

Sorry, I forgot to update it in the second place too :oops: – I’ve now corrected the source on my site.

Best regards,

Thanks Ken, that did it!

I’m having the same problem. It appears only the Zone is coming up even though the url for mytown is working. I added the : in both places. What am I missing?



KenM (strange, I have KMT as my initials :slight_smile:

It looks like your ‘forecast.txt’ script is not being overwritten … use your IIS control panel to set the permissions for allow read/write to that file and your forecast should work ok.

<b>Warning</b>:  readfile(c:\inetpub\wwwroot) [<a href='function.readfile'>function.readfile</a>]: failed to open stream: Permission denied in <b>C:\Inetpub\wwwroot\extendedforecast2.php</b> on line <b>90</b>

was the contents of your ‘forecast.txt’ file.

Best regards,

Added those permissions but i still seem to have the same problem. You still see the same thing?


Hmmm. Now your forecast.txt file has a Carter Lake, IA forecast from Feb, 2007 – I don’t think the script can write your forecast.txt file yet. Would you mind sending me the source for your advforecast2.php file so I can take a look ( webmaster [at] ).

Best regards,


You are ahead of the game, yet again! I was going to try and write something for the temporary file stuff but you have already done it. I will have to review your code to see how it’s done.

Thanks for all your contributions to this board!

I’m still working out the fact I can’t get anything to write to the forecast.txt file. IIS permissions to the file seem correct. going to try some test php to write a simple text to the file.


You might try adding


to the start of the script and see what it says. Also, your php.ini may have a setting that prevents writing local files – like Safe_mode = on , but I think it’s still the permissions.

Best regards,

Ah success… fixed my permission problems, however I still only get the default zone not my actual town forecast.


I think I’ve figured it out. Your

$filename = ""; 

is getting a redirect (302) to so advforecast2.php thinks your primary (point-forecast) page is not available, so it automatically falls back to the zone-forecast page.

Try changing your code to

$filename = "";

and see if that fixes the issue.

Meanwhile, I’ll work on doing a bit of coding on it to follow the first 302 (Location: …) and refetching.

Let me know if the URL change does the trick.

Best regards,