WD Avg/Extreme Sample Snippet
THIS IS VERSION II
Introduction
This is a code snippet is designed to be called by another PHP webpage that first includes it and then calls it using the display_data command. It is not intended to be a stand alone script.
PLEASE READ THE ENTIRE PAGE AS IT INCLUDES INFO ON HOW TO USE THE SCRIPT..
It also shows you a sample page and how that sample page works.
The ONLY HTML output by the script itself is base code using style CSS tags that the calling HTML script either needs to have inside of it, or called from an external CSS file.
This page has examples of the script snippet itself, and a sample HTML PHP file that calls it to may it "pretty". You can use the two scripts combined to add to your existing website by taking the sample.php file and adding it to your current page system.
It is assumed that the user has at least a basic idea of HTML and how to load and edit a PHP file if needed. It is also assumed that the user is using the English output of the Weather-Display Daily Report HTML file. If you are using a different langauge, you will need to change the script to "see" the different output.
Original WD HTML file
The following link shows what an original WD Daily Report HTML file looks like. This is the same file that will be parsed by the subsequent scripts.
Original WD Exported HTML File - December2007.htmThis is what the current exported Weather-Display HTML Daily Report looks like. What the following script does is strip out the data and represent it with CSS tag's so that you could enhance its look and make it match your website.
AvgExtract.php Script
The following is a link to the source of the AvgExtract.php script. Note that if you run it, NOTHING will happen. It is designed to be loaded with a require PHP statement and then called using its display_data command.
Source Code of AvgExtract.php Script
AvgExtract.txt Script Source CodeSample HTML PHP Script that uses the AvgExtract.php script
Below is an active link that shows an example of how the script could be used. This example is a small PHP script that provides the wrapper HTML needed to display the output of the script using CSS to make it "pretty".
Sample Page
Sample Web Page showing usage of the AvgExtract.php ScriptSource Code for Sample Page
Source code of Sample Web Page that uses AvgExtract.php ScriptBefore you can use this script...
Before you can use the script, you need to make some changes...
Changing where the script looks for data
First you need to change the $website variable in the AvgExtract.php script to point to where your data is located. The source code you see is pointing where MY data is located from the scripts area.
Copy the Sample
If you are just starting out, you can copy the sample.php file to get a simple page that you can use to try it... Note that the sample.php file uses require_once to load the script but uses the display_data command to make it output anything.
Using Metric Rain?
You need to change the $level2 array in the top of the AvgExtract.php script:
$level2 = array(
array(",ET", 2),
array("Sunshine hours month to date",6),
array("Sunshine hours year to date",6),
array("in. on day",0),
);$level2 = array(
array(",ET", 2),
array("Sunshine hours month to date",6),
array("Sunshine hours year to date",6),
array("mm on day",0),
);Make Change to the CSS
To make it match your website, you need to make changes to the included external CSS file, or add your own to your own scripts. The following CSS tags are used in this script. Please note that this CSS is showing a Class ID of ndaily which is because the sample.php page is using it to keep it separate from any other CSS that might be in effect.
Source for the CSS
Source code of AvgExtract.css/* Sample CSS for AvgExtract.php Script */
#ndaily {
font-family: verdana;
font-color: #22464F;
}
#ndaily a {
font-size: 80%;
text-decoration: none;
color: #4A2409;
font-weight: bold;
padding: 1px;
}
#ndaily a:visit {
text-decoration: none;
color: #4A2409;
font-weight: bold;
padding: 1px;
}
#ndaily a:hover {
text-decoration: underline;
color: #4A2409;
font-weight: bold;
text-decoration: underline;
}
#ndaily h1 {
font-size: 130%;
background-color: #C09070;
padding: 2px;
width: 60%;
border: 1px solid #4A2409;
border-right: 3px solid #4A2409;
border-bottom: 3px solid #4A2409;
text-align: center;
}
#ndaily h2 {
font-size: 110%;
}
#ndaily h3 {
font-size: 120%;
background-color: #C09070;
padding: 2px;
width: 50%;
border: 1px solid #4A2409;
border-right: 3px solid #4A2409;
margin: 14px 5px 14px 0px;
border-bottom: 3px solid #4A2409;
text-align: center;
}
#ndaily .recap {
font-size: 120%;
background-color: #C09070;
padding: 2px;
width: 60%;
border: 1px solid #4A2409;
border-right: 3px solid #4A2409;
margin: 14px 5px 14px 0px;
border-bottom: 3px solid #4A2409;
text-align: center;
}
#ndaily .tbl {
width: 75%; border: 1px solid #4A2409;
border-collapse: collapse;
border-right: 4px solid #4A2409;
border-bottom: 4px solid #4A2409;
}
#ndaily .left {
color: #4A2409;
padding-left: 5px;
font-family: verdana;
width: 210px;
border: 1px solid #4A2409;
background-color: #FAFACE;
text-align: left;
}
#ndaily .right {
color: #4A2409;
padding-left: 5px;
font-family: "courier new", monospace;
font-size: 90%;
border: 1px solid #4A2409;
background-color: #FAFACE;
text-align: left;
}
#ndaily .rtbl {
width: 50%; border: 1px solid #4A2409;
border-collapse: collapse;
border-right: 4px solid #4A2409;
border-bottom: 4px solid #4A2409;
}
#ndaily .rain {
text-align: center;
color: #4A2409;
padding-left: 5px;
font-family: verdana;
width: 50%;
border: 1px solid #4A2409;
background-color: #FAFACE;
} Using a Different Language?
The parsing used in this script was based on the English output of the WD Daily Report HTML. As such, it does its thing based on what is sees when it goes through the file.
To use a different language, you will need to change two things in the script....
Level1 and Level2 Arrays
The script uses the Level1 and Level2 Arrays to know what the spacing is for that data. The left side of the array is the text on the line, and the right side is the number of words to the data...
// Arrays to Format Things with
$level1 = array(
array("Average temperature",3),
array("Average humidity",3),
array("Average dewpoint",3),
array("Average barometer",3),
array("Average windspeed",3),
array("Average gustspeed",3),
array("Average direction",3),
array("Rainfall for month",4),
array("Rainfall for year",4),
array("Maximum rain per minute",5),
array("Maximum temperature",3),
array("Minimum temperature",3),
array("Minimum pressure",3),
array("Maximum pressure",3),
array("Maximum windspeed",3),
array("Maximum gust speed",4),
array("Maximum humidity",3),
array("Minimum humidity",3),
array("Maximum heat index",4),
array("Maximum rain per minute",5),
array("Growing degrees days",5),
);
$level2 = array(
array(",ET", 2),
array("Sunshine hours month to date",6),
array("Sunshine hours year to date",6),
array("in. on day",0),
);String Checks in the Code
This is a bit harder... there is a section of code that looks for specific terms used in the HTML.... you will need to change the english text, to match what is output in your language. This is vital otherwise the sections will not be output properly.
You also need to match the preg_match statements that are there as well as that is how it knows what Day is being processed. This data is then used to create the chart links and to know what month is being processed.
Script In Action
Below are a few sites that picked up the script and did some changes with it to make it fit their weather pages.
Discussion
There is some discussion about this script in the Weather-Watch forums in the following thread.


NEXRAD Radar & Satellite Maps



© 1992-2010 Copyright TNET Services, Inc.