Skip to main content.
^^

TNET Weather Station Notebooks - PHP Weather FAQ's

Recently we added a new feature to our website which allows us to create Weather Facts. We can add to the facts as as needed and they are instantly available on the site in random order.

At the bottom of this page is a live example of the Weather Facts we are using


get-facts.php


<!-- Get Facts PHP Script -->
<?
    $f_name = "./facts.txt";

    $fp = fopen($f_name,"r");
    $f_content= fread($fp, filesize($f_name));
    fclose($fp);

    $fnotes = explode(":::",$f_content);


    shuffle($fnotes);

    $i=0;
    while(list(,$code) = each($fnotes)) {
        $i++;
                if ($i>=$max) {
                        break;
                }
    }
?>
    <?=$code;?><br/> <br>/
Updated 8/19/2006

Sample Facts Data File

The fact file itself is a flat file with a delimiter at the end of each entry. The delimiter can be any unique set of characters, but we choose ::: which is basically never found in regular text. If you change the delimiter, you need to change the function above to match.

Sample Data File

<strong>RAIN FALL</strong><br/>In Arizona, typically, the heaviest rain falls 
during the summer thunderstorm season, or Monsoon, in our state. The rain 
can accumulate very quickly, resulting in flooded streets or washes, and 
can even cause deaths via flash flooding. In Phoenix, the greatest 
rainfall in a 24 hour period was 4.98 inches on July 1-2, 1911. 
This total is quite a bit less than the Arizona record of 11.4 
inches, which fell on Workman Creek (near Globe) on September 4-5, 1970.:::
<strong>COLD TEMPS</strong><br/>Hawley Lake recorded Arizona's coldest 
temperature of 40° below zero on January 7, 1971. The coldest temperature recorded in 
Phoenix was 16°, set on January 7, 1913. Phoenix Sky Harbor Airport, where the 
official temperature for Phoenix is recorded, rarely gets below freezing(32°F).:::

Note that you can include regular html code in the file and it will be used when displayed on the page. The delimiter is on the end of the text.

Adding the function to other pages

Below is the function we then call from each page we want to have a random weather fact section on

	<p><?php include("get-facts.php"); ?></p>

You can then add what ever formatting you want to the above code to get the look and feel you want from the data.

Below is an actual sample of it in action.

Arizona Random Weather Facts

HURRICANE FACTS
Hurricane Facts: 1961 was the last time two Category 5 hurricanes formed in the same year. 1960 was the last time two Category 5 hurricanes formed and eventually made U.S. land fall. 2005 has now matched that with Katrina and now Rita.

  Goto Top Of Page
Web Design by TNET   © 1992-2008 Copyright TNET Services, Inc.
Home | Privacy Statement | Site Map | About Us - TNETWebGen v2.6.1
Some images and designs (SM) TNET Services, Inc.
SWN Member   USA Weather Finder