Hi Keith,
I think you may have a misconception about how web services and scripting work. When a browser makes a request to a web server using http://.... it begins a transaction that completes when the browser has finished loading the requested item (and any parts also described by the embedded HTML markup). Once the loading is complete, the connection between browser and web server is terminated, and there is no 'memory' involved.
What the browser requests using http://... is usually a file that contains HTML markup which may instruct the browser to do additional requests to obtain scripts (both JavaScript and CSS styling) and images to make the page render in the browser.
The initial page requested may also have been constructed (by the web server) using PHP to produce the HTML on the page.
The JavaScript referenced by the page will execute only on the browser (not on the webserver), and the PHP is processed only on the webserver (not in the browser). The DOM you refer to only exists in the browser and so can be modified by JavaScript, but not by PHP (which can only create HTML markup or in-page JavaScript to be executed by the browser).
So.. what you are asking for is not really feasible since the whole web thing is a transaction, not a 'state', so there is no permanency involved in the basic protocol. The 'memory' would have to be provided using a database of some kind and PHP scripting on the webserver.
For your example to have a running list of rainy day dates+amounts, that sounds much like the NOAA-style climate report (which I think is not a current feature of WeatherCat) but looks like this MONTHLY CLIMATOLOGICAL SUMMARY for JUN. 2013
NAME: KCASARAT1 CITY: Saratoga STATE: CA
ELEV: 375 ft LAT: 37? 16' 28" N LONG: 122? 01' 23" W
TEMPERATURE (?F), RAIN (in), WIND SPEED (mph)
HEAT COOL AVG
MEAN DEG DEG WIND DOM
DAY TEMP HIGH TIME LOW TIME DAYS DAYS RAIN SPEED HIGH TIME DIR
------------------------------------------------------------------------------------
1 72.8 94.7 2:55p 52.8 5:55a 3.2 10.9 0.00 0.9 14.0 4:00p NNW
2 67.0 85.9 1:35p 53.5 6:25a 3.6 5.6 0.00 0.7 11.0 1:55p N
3 65.1 83.4 1:35p 49.4 5:50a 5.2 5.3 0.00 0.8 11.0 3:25p NE
4 64.2 77.7 1:45p 53.6 5:10a 4.3 3.5 0.00 1.1 13.0 4:40p NNW
5 64.0 74.6 1:35p 56.5 4:20a 3.9 2.9 0.00 1.1 13.0 1:40p N
6 66.2 81.4 4:50p 55.9 6:10a 3.8 4.9 0.00 0.8 12.0 3:40p N
7 73.5 93.6 4:15p 56.5 6:30a 2.5 11.0 0.00 0.5 10.0 1:45p N
8 62.4 68.9 12:05a 58.9 6:15a 1.0 0.1 0.00 0.0 1.0 7:10a NNW
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-------------------------------------------------------------------------------------
66.9 94.7 1 49.4 3 27.5 44.2 0.00 0.7 14.0 1 N
(example produced by WeatherLink).
You can also use the STMONTHLY$ tag to generate a complete set of month-to-date statistics that can be parsed by PHP, values selected and displayed on your page. To be functional, you would need to have WeatherCat process and upload a template page with the STMONTHLY$ tag in it, and write a PHP script to slice/dice the output as you desire.
Hope this helps...
Best regards,
Ken
Well, that's kinda a tall order since I don't know how much PHP you're already familiar with. How about we approach "To be functional, you would need to have WeatherCat process and upload a template page with the STMONTHLY$ tag in it, and write a PHP script to slice/dice the output as you desire."
with some code examples on how the problem might be solved (I find I learn best by seeing the code :)
The basic structure for solving a 'get some data and present it' problem with PHP can be divided into three basic parts:
1) get some raw-data from somewhere
2) parse the data into PHP variables -- this can be the tricky part
3) use PHP echo/print statements with HTML to display the desired data on the page.
Remember that a PHP page is just an HTML page with some embedded PHP code in it, and everything between a starting <?php and the next ending ?> is treated as PHP code by the interpreter and is output as a 'null'/non-existent in the resulting HTML (unless the PHP code uses print/echo statements to cause output to appear).
For (1), 'get some raw-data', here's where the webtags for WeatherCat come in. A simple statement like <?php $rawdata = 'STMONTHLY$';
?> should (when the page is processed and uploaded to your website), cause $rawdata to have contents like Saratoga-weather.org
Day TempHi TempLo TempAv HeatHi HeatLo HeatAv ChillHi ChillLo ChillAv DewPHi DewPLo DewPAv HumHi HumLo HumAv PresHi PresLo PresAv R/hHi R/hLo R/hAv Rain AvWsHi AvWsLo AvWsAv GustHi GustLo GustAv WDir WRun SolHi SolLo SolAv UVHi UVLo UVAv
1 94.7 52.8 72.8 91.6 52.8 72.6 94.7 52.8 72.8 56.3 45.2 51.5 86 20 54 29.94 29.78 29.85 0.00 0.00 0.00 0.00 6 0 1 14 0 2 221 22.4 948 0 336 10.5 0.0 2.7
2 85.9 53.5 66.9 84.6 53.5 67.2 85.9 53.5 66.9 57.7 48.6 53.2 89 35 64 29.79 29.68 29.74 0.00 0.00 0.00 0.00 4 0 1 11 0 2 128 18.0 933 0 326 9.7 0.0 2.5
3 83.4 49.4 65.2 82.5 49.4 65.9 83.4 49.4 65.2 58.4 46.0 52.5 91 37 67 29.86 29.72 29.78 0.00 0.00 0.00 0.00 4 0 1 11 0 2 88 20.1 922 0 321 8.9 0.0 2.3
4 77.7 53.6 64.3 79.0 53.6 65.2 77.7 53.6 64.3 58.2 50.0 53.8 91 48 71 29.97 29.85 29.90 0.00 0.00 0.00 0.00 5 0 1 13 0 3 129 26.8 897 0 309 9.1 0.0 2.4
5 74.6 56.5 63.9 77.5 56.5 65.3 74.6 56.5 63.9 57.0 51.4 53.6 85 51 71 29.99 29.92 29.96 0.00 0.00 0.00 0.00 4 0 1 13 0 3 108 27.2 908 0 310 9.8 0.0 2.6
6 81.4 55.9 66.2 81.6 55.9 66.8 81.4 55.9 66.2 58.9 50.8 54.4 85 44 68 29.96 29.85 29.91 0.00 0.00 0.00 0.00 4 0 1 12 0 3 121 19.9 906 0 297 10.3 0.0 2.6
7 93.6 56.5 73.7 94.3 56.5 74.1 93.6 56.5 73.7 62.5 52.4 57.1 87 33 60 29.89 29.73 29.81 0.00 0.00 0.00 0.00 3 0 0 10 0 2 184 11.5 926 0 325 10.3 0.0 2.7
8 76.7 58.9 65.1 78.5 58.9 65.6 76.7 58.9 65.1 60.2 50.3 54.9 84 55 70 29.75 29.71 29.73 0.00 0.00 0.00 0.00 0 0 0 3 0 0 295 0.0 560 0 157 3.4 0.0 0.7
Monthly High 94.7 58.9 73.7 94.3 58.9 74.1 94.7 58.9 73.7 62.5 52.4 57.1 91 55 71 29.99 29.92 29.96 0.00 0.00 0.00 0.00 6 0 1 14 0 3 - 27.2 948 0 336 10.5 0.0 2.7
Monthly Low 74.6 49.4 63.9 77.5 49.4 65.2 74.6 49.4 63.9 56.3 45.2 51.5 84 20 54 29.75 29.68 29.73 0.00 0.00 0.00 0.00 0 0 0 3 0 0 - 0.0 560 0 157 3.4 0.0 0.7
Monthly Average 83.5 54.6 67.3 83.7 54.6 67.8 83.5 54.6 67.3 58.7 49.3 53.9 87 40 66 29.89 29.78 29.83 0.00 0.00 0.00 0.00 4 0 1 11 0 2 159 18.2 875 0 298 9.0 0.0 2.3
Monthly Total
which is ripe for parsing.
(2) Let's slice and dice that data into convenient arrays by using something like <?php $datalines = explode("\n",$rawdata); ?> which puts those lines into an array $datalines based on the new-line character.
Then a <?php
foreach ($datalines as $i => $line) { ... } ?> can walk through each separate $line and some processing can be done like <?php
$Rain = array(); // blank storage area for rain values
foreach ($datalines as $i =>$line ) {
preg_split("|\s+|",$line,$vals); // carve up the lines into values by splitting on whitespace
if(isset($vals[0]) and preg_match('|^\d+$|',$vals[0]) ) {
// got one of the value lines we're looking for -- save it away in the $Rain array
$Rain[$vals[0]] = $vals[22]; // the rain total field is number 22 (counting from 0) in the record
}
}
// now the $Rain[] array is ordered by day with the value of rain for that day as the contents of that array entry.
?>What we did above was walk through each line (with the foreach), use preg_split to put the individual values on that line into an array $vals, see if the first $vals is numeric (meaning a day-of-the-month) and if so, collecting the data we wanted for later use.
Now in part 3 (present the data) you can do something simple like <?php
foreach ($Rain as $day => $amount) {
print "Day: $day had $amount of rain.<br/>\n";
}
?>to print the list.
Hopefully this will give you enough fodder to start your PHP exploration. Pretty much all of my 'get-data-and-format' scripts follow this general structure so using my scripts as examples is also recommended as ways of doing stuff with PHP.
Best regards,
Ken