PHP: Difference between revisions

From Cumulus Wiki
Jump to navigationJump to search
640 bytes added ,  05:19, 19 May 2018
m
m (→‎An example of a Cumulus template using PHP: added a little explanation of code)
Line 155: Line 155:


</pre>
</pre>
Note that only excerpts from the code are shown.  Note the two ways of getting PHP to output HTML code, either by using separate echo commands for each line or using the "heredoc" approach so that one echo can be applied to multiple lines.  In the latter way, the syntax allows a space after echo and after <<< but does not allow any other spaces (or tabs) in the two enclosing lines (that precede and follow all the listed output).
Note that only excerpts from the code are shown.  Earlier in this article we saw the shorthand to output content of a variable into HTML used '&lt;?=', now we see the two ways of getting PHP to output more complicated HTML code, either by using separate echo commands for each line or using the "heredoc" approach so that one echo can be applied to multiple lines.  In the latter way, the syntax requires a space after echo and after <<< but does not allow any other spaces (nor tabs) in the two enclosing lines (that precede and follow all the listed output). PHP is even more useful if we want to use conditional instructions or loops. For example, by default Cumulus will set the time-stamp of the highest hourly rain in a day to your rollover time if there is no rain in the day. A conditional could test the PHP variable containing the highest hourly rain, and only output the time-stamp if that conditional is not zero:
<pre>
&lt;th>Rainfall (Highest Hourly)</th>
&lt;td>&lt;?= $hourlyrainTH;?>
&lt;td>
&lt;?php
if($hourlyrainTH) echo $ThourlyrainTH;
?>
</td>
</pre>


== Other PHP examples ==
== Other PHP examples ==
5,838

edits

Navigation menu