Php webtags: Difference between revisions

1,527 bytes added ,  07:37, 12 October 2018
m
→‎Web tag Complications: Minor correction re 'may contain dashes'; some other parts explained in more detail
(→‎Option 2: Multiple PHP Variables: add important note re MX)
m (→‎Web tag Complications: Minor correction re 'may contain dashes'; some other parts explained in more detail)
Line 7: Line 7:
= Web tag Complications =
= Web tag Complications =


*Some web tags contain content that never changes, I will leave you to work out which these are; equally some web tags identify the month or year and only change when a new month or new year starts. It does not make for efficient use of resources if you make both PHP and Cumulus process every web tag each time Cumulus does a real time update. So although this article talks about a single script assigning Cumulus web tags to PHP variables, it actually makes better sense to have multiple scripts, each processed only when the tags they contain may change. How to arange this is beyond the scope of this article, you need to have a very good understanding of  PHP and Cumulus and you might seek help via the support forum.
*In early versions of Cumulus, its web tags did not take parameters and it was easy to assign each web tag to a variable that any data transfer approach could use;
*In early versions of Cumulus, its web tags did not take parameters and it was easy to assign each web tag to a variable that any data transfer approach could use;
*From version 1.9.3 various web tags (such as "Recent History") always take parameters, others (like those reporting times and/or dates) can take parameters.  
*From version 1.9.3 various web tags (such as "Recent History") always take parameters, others (like those reporting times and/or dates) can take parameters.  
**There are now a vast number of possible combinations and it would be in-efficient for all those combinations to be generated whether needed or not.  
**There are now a vast number of possible combinations and it would be in-efficient for large numbers of those combinations to be generated whether needed or not.  
**Consequently anyone devising a sample file in any of the formats listed below can only guess which parameters are most useful.
**Consequently anyone devising a sample file in any of the formats listed below can only guess which parameters are most useful.
**Because of this 'guessing'; '''do not assume''' that a file from some one else, will meet your requirements ''out of the box'', you must be prepared to edit it.
**Because of this 'guessing'; '''do not assume''' that a file from some one else, will meet your requirements ''out of the box'', you must understand the script language and be prepared to edit the file supplied into one that meets your own requirements.
*Note that Cumulus web tags can return either numerical or string information, and when returning string information Cumulus can include embedded quotes: e.g. <code>$LatestError = "Latest Error: 'Some filename was locked" recorded';</code> as the embedded ones are double quotes, single quotes are used in <code>$LatestError='<#LatestError>';</code> in the template file as delimiters for the whole string. Equally Longitude and Latitude web tags by default label the minutes and seconds part with the same symbols as used by quotes, so we have to choose the alternative decimal notaion <code>$longitude=<#longitude dp=5>;</code>
*When editing the file remember that Cumulus web tags can return either numerical or string information, when using the script variables you may wish to do numeric calculations or comparisions, and these might behave differently if numeric information is processed as a string (for example the month of March as a number returns '3', but as a string may return '03', some comparisons don't recognise those are same).
*Depending on how long you have been running Cumulus, some webtags that might be expected to return numerical information may contain dashes. You may get an error if that particular PHP variable is treated as numerical.
**Also when returning string information Cumulus can include embedded quotes: e.g. <code>$LatestError = "Latest Error: 'Some filename was locked" recorded';</code> as the embedded ones are double quotes, single quotes are used in <code>$LatestError='<#LatestError>';</code> in the template file as delimiters for the whole string. Equally Longitude and Latitude web tags by default label the minutes and seconds part with the same symbols as used by quotes, so we have to choose the alternative decimal notation <code>$longitude=<#longitude dp=5>;</code>
*Remember some webtags are specific to particular station types and may not return any useful information for your station.
**Some webtags that might be expected to return numerical information may contain dashes instead sometimes. You may get an error if that particular PHP variable is treated as numerical. As an example on the first day of a month <code>$monthHighDailyTempRange='<#MonthHighDailyTempRange>';</code> will return dashes as that particular item is not calculated by Cumulus until at least one complete day is available.
*Remember some webtags are specific to particular station types and may not return any useful information for your station. For example <code>$light=<#Light>;</code> is a value that only applies to those Fine Offset stations that have a solar sensor and not to any other make or type.
*Yet another complication (for Cumulus 1 users) is that the values for  [[Webtags#Time.2FDate_.27format.27_Parameter|formatting parameters]] can include double and single quotes, but any assignment to a PHP variable requires the value to be quoted so it is treated as a string.  There are two ways round this, one is to concatenate several uses of the same Cumulus web tag to build up the required layout without using both versions of quotation marks within any single formatting value e.g. <code>$LastDataReadTDM='<#LastDataReadT format=h:nn'.' on '.'<#LastDataReadT format="d mmm">';</code>, and the other is to use the PHP 'heredoc' approach - see PHP manual.
*Yet another complication (for Cumulus 1 users) is that the values for  [[Webtags#Time.2FDate_.27format.27_Parameter|formatting parameters]] can include double and single quotes, but any assignment to a PHP variable requires the value to be quoted so it is treated as a string.  There are two ways round this, one is to concatenate several uses of the same Cumulus web tag to build up the required layout without using both versions of quotation marks within any single formatting value e.g. <code>$LastDataReadTDM='<#LastDataReadT format=h:nn'.' on '.'<#LastDataReadT format="d mmm">';</code>, and the other is to use the PHP 'heredoc' approach - see PHP manual.


5,838

edits