Php webtags: Difference between revisions

3,613 bytes added ,  10:52, 20 April 2020
m
Line 87: Line 87:
**A template file to do this is also called ''CUtags.txt'' and it can be downloaded from [http://saratoga-weather.org/wxtemplates/install.php Saratoga-Weather.org].
**A template file to do this is also called ''CUtags.txt'' and it can be downloaded from [http://saratoga-weather.org/wxtemplates/install.php Saratoga-Weather.org].
**That download includes elements for the recent history tags at 5, 10, 15, 20, 30, 45, 60, 75, 90, 105 and 120 minutes. If you want older values or values at other times, then you will need to add these to the array yourself.
**That download includes elements for the recent history tags at 5, 10, 15, 20, 30, 45, 60, 75, 90, 105 and 120 minutes. If you want older values or values at other times, then you will need to add these to the array yourself.
== Usage ==
Use the PHP [http://www.w3schools.com/PHP/php_includes.asp include/require] command to include the Cumulus web tags into your PHP file.  Then where you would insert a web tag if you were writing a template, you insert a command to "echo" the php variable <pre><?=$PHP_variable_name[any_index_needed];?></pre>
The "=" in the above example is shorthand for " echo " with the spacing shown. In most of the ready made files listed for download on this page the PHP variable names are either identical to their [[webtags]] equivalent or have a name that reflects the output parameters selected, but of course if you are editing the file you might choose different names. For example in provided code, the Cumulus webtag <tt><#forecast></tt> would be referred to as <tt>$forecast</tt> in your PHP file.
However the beauty of using script (PHP or another) is that you can add other aspects of the script language like conditions and control what HTML is output. For instance if a PHP variable tells you it is not raining you might leave out displaying the current rain rate. Or if it is night time you might report fewer derivatives than if it is day time. If it is the first day of a month, then you can leave out the rows in your table that would report the highest and lowest for the month that are not yet defined. Such php script might look something like this example that wants alternating rows to look different and has to adapt that if one row is left out:
<pre>
<?php if ($show_apptemp){ ?>
              <tr class="even">
                  <td><span lang="en">Apparent Temperature</span></td>
                  <td style="text-align:right;"><span class="ajax" id="ajaxapptempNoU"><?php echo $RT_apptemp ?></span></td>
                  <td><?php echo $tempunit; ?></td>
              </tr>
              <tr class="odd">
                  <td><span lang="en">Heat Index</span></td>
                  <td style="text-align:right;"><span class="ajax" id="ajaxheatidxNoU"><?php echo $RT_heatindex ?></span></td>
                  <td><?php echo $tempunit; ?></td>
              </tr>
              <tr class="even">
                  <td><span lang="en">Humidex</span></td>
                  <td style="text-align:right;"><span class="ajax" id="ajaxhumidexNoU"><?php echo $RT_humidex ?></span></td>
                  <td><?php echo $tempunit; ?></td>
              </tr>
          <!--    <tr class="odd">
                  <td><span lang="en">Indoor Temperature</span></td>
                  <td style="text-align:right;"><span class="ajax" id="ajaxintempNoU"><?php echo $RT_intemp ?></span></td>
                  <td><?php echo $tempunit; ?></td>
              </tr> -->
<?php }else{ ?>
              <tr class="even">
                  <td><span lang="en">Heat Index</span></td>
                  <td style="text-align:right;"><span class="ajax" id="ajaxheatidxNoU"><?php echo $RT_heatindex ?></span></td>
                  <td><?php echo $tempunit; ?></td>
              </tr>
              <tr class="odd">
                  <td><span lang="en">Humidex</span></td>
                  <td style="text-align:right;"><span class="ajax" id="ajaxhumidexNoU"><?php echo $RT_humidex ?></span></td>
                  <td><?php echo $tempunit; ?></td>
              </tr>
              <tr class="even">
                  <td><span lang="en">Indoor Temperature</span></td>
                  <td style="text-align:right;"><span class="ajax" id="ajaxintempNoU"><?php echo $RT_intemp ?></span></td>
                  <td><?php echo $tempunit; ?></td>
              </tr>
<?php } ?>
</pre>


= The different Main Approaches to data transfer =
= The different Main Approaches to data transfer =
5,838

edits