User Tools

Site Tools


uphp:uphp_language_basics

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
uphp:uphp_language_basics [2019/07/22 06:30]
admin
uphp:uphp_language_basics [2019/07/22 06:52]
admin old revision restored (2018/09/05 13:23)
Line 1: Line 1:
-======uPHP Blockly Development======+======uPHP Language Basics======
  
-Blockly is a visual programming editor developed by Google.  We have integrated blockly with all the uPHP functions to make programming easier.  Blockly scripts can be automatically hooked to various parts of the system from the interface.+The following sections describe how to work with uPHP scripts.
  
-Visual uPHP scripts need to be generated or run in order for the uPHP code to be created.  Visual uPHP scripts have the extension .cgx whereas generated scripts will have a .cgi extension.+=====uPHP Tags=====
  
-{{:uphp:blockly_home.png?1000|}}+When [[hardware:wattmons|Wattmon]] parses a file, it looks for opening and closing tags, which are ''<?'' and ''?>'' respectively. This tells [[hardware:wattmons|Wattmon]] to start and stop interpreting the uPHP code between them. Parsing in this manner allows you to integrate script code within an HTML file as everything outside of a pair of opening and closing tags is ignored by the uPHP parser.
  
-To access the editorgo to File Manager and click the New Script button in the folder you wish to create the script.+<code php> 
 +Some text 
 +<? 
 +  print(‘hellouPHP’); 
 +?> 
 +Some more text 
 +</code>
  
-The visual editor is visible in the Designer tab.  You can use the left navigation to drag code blocks onto the editor area and link them up accordingly.+In addition, you can integrate multiple code blocks within a page, even if it is within a uPHP code block For example if you wished to display a block of HTML based on a uPHP condition, it would go something like this:
  
-To change the file name or save as a different name, edit the File box at the top of the page and hit Save.  To generate the .cgi file, click Generate.  If you wish to generate and preview the page, click Run.+<code php> 
 +<? 
 +  If ($mycondition > 5) { 
 +    ?> This will only be output if my condition > 5 <? 
 +  } else { 
 +    ?> This will be output if the first condition is not true<? 
 +  
 +?> 
 +</code> 
 +  
 +=====Instruction Separation=====
  
-If the script is to be inserted into the WattmonOS system, select the appropriate Hook in the drop down This could be any of the following: +As in C and PHP, uPHP requires instructions to be terminated with a semicolon at the end of each statementThe closing tag of a block of uPHP code automatically implies semicolon; you do not need to have a semicolon terminating the last line of a uPHP block. The closing tag for the block will include the immediately trailing newline if one is present.
-^ Hook              ^ Description                                          ^ +
-| Run once at boot  | This script will be run one time upon system reboot +
-| Run once per second | The script will be run once second | +
-| Run once per minute | The script will be run once minute | +
-| In Ajax Generation | The script will be run while generating the ajax data for the home page The format for this is very specific.  Read up on [[Ajax Generation]] here. | +
-| In Home Page | The script will be included as a widget in the home page.  Customize the options by clicking the Options button.  You can output any standard HTML or Javascript here|+
  
 + 
 +=====Comments=====
 +
 +uPHP supports 'C', 'C++' and Unix shell-style (Perl style) comments. For example:
 +
 +<code php>
 +<?
 +  // comment 1
 +  $x=1;
 +  # comment2
 +  $x=2;
 +  print($x);
 +  /* comment 3 */
 +  $x=3;
 +  print($x);
 +?>
 +</code>
 +
 +The "one-line" comment styles only comment to the end of the line or the current block of uPHP code, whichever comes first. This means that HTML code after ''%%//%% ... ?>'' or ''# ... ?>'' WILL be printed: ''?>'' breaks out of uPHP mode and returns to HTML mode, and ''%%//%%'' or ''#'' cannot influence that.
 +
 +'C' style comments end at the first ''*/'' encountered. Make sure you don't nest 'C' style comments. It is easy to make this mistake if you are trying to comment out a large block of code.
 + 
 +<code php>
 +<?
 +/*
 +echo 'This is a test'; /* This comment will cause a problem */
 +echo 'Print this also';
 +*/
 +?>
 +</code>
  
 =====Programmer Reference===== =====Programmer Reference=====
uphp/uphp_language_basics.txt · Last modified: 2021/09/13 05:57 (external edit)