PHP: Difference between revisions

798 bytes added ,  19 May 2018
m
→‎An example of a Cumulus template using PHP: added a little explanation of code
m (→‎Using PHP scripts not processed by Cumulus: replace 'as above' by 'normal')
m (→‎An example of a Cumulus template using PHP: added a little explanation of code)
<tr>
&lt;th title="Darkness times calculated by PHP">Darkness starts</th>
&lt;td>&lt;?php=($darkness_start->format('g:i a'));?></td>
echo ($darkness_start->format('g:i a'));
?></td>
</tr>&lt;tr>
&lt;th>Darkness ends</th>
&lt;td>&lt;?php= ($darkness_end->format('g:i a'));?></td>
echo ($darkness_end->format('g:i a'));
?></td>
</tr>
</pre>
This example shows that PHP instructions can be inserted into a normal HTML page simply by preceding the PHP instructions by the tag &lt;?php, you then return to HTML using the tag ?&gt;. All PHP instructions end in a semicolon (;) and to concatenate two strings you use full stop (.) so to concatenate something extra to an existing string you use full stop equals (.=). If the instruction is simply to place the contents of a PHP variable into HTML, the standard is to precede the PHP variable by &lt;?=. Normally, PHP variables use names that start with dollar sign ($). Comments may be inserted into PHP code in several ways, but double slash (//) is used for annotations where you want the instruction before to be processed, but then the PHP parser should ignore everything after the double slash in the same line.
 
Incidentally, do look at the Cumulus FAQ or [[Webtags#Day.2FNight.2FSun.2FMoon|web tags]] where what Cumulus reports as Sunrise time is explained as the last one before any midnight GMT, and what it reports as Sunset time refers to that occurring after the midnight GMT, so they are frequently on different days.
5,838

edits