JANOS Help System: [Commands] [Topics] [Tech Support] [Printable Manual] [Search]
Variables Scripting DESCRIPTION JANOS scripting is modeled after PHP and just as is PHP variable names always start with the dollar sign '$' character. By convention the next character in a name must be either the underscore '_' or an upper or lowercase letter in the set [a-zA-Z]. Varialbe names are case-sensitive. The name can be any length and the remaining characters may also be a digit [0-9]. TYPES Variables store information that is needed by the script. These information types are supported. * Booleans * Integers * Float Point Numbers * Strings * Arrays * NULL Script is loosely typed. You do not declare the variable type. That is defined by what you store in them. A variable can contain different types at different times. In fact you generally needn't worry about conversions either. Except for rare situations this is handled for you. Boolean variables store either True or False . These literal terms are case-insensitive. Boolean variables are great as flags to control script operation or to store the results of comparisons. Integers are in the range from -2,147,483,648 to +2,147,483,647 inclusive. An overflow can occur when a result exceeds the largest integer value at either end of the range. Floating point values are supported to 6 significant digits. The IEEE 754 format is used. Care should be used with floating point as the limited precision can lead to rounding errors and the error can easily compound and accumulate. Strings can be of any length and can contain the values from 0x00 to 0xff inclusive. Binary data can be stored by String variables. Arrays are name-value pairs with the name being the array index and the value any variable type. Arrays may be multi-dimensional as the values can be arrays as well. STRINGS String literals are defined using single quotation marks (') as follows: 'This is a string literal' Escape sequences such as ' ' are not converted within literals. Everything between the single quotes including line breaks are part of the string. The only escape sequence recognized is that escaping a single quote itself. bruce_dev /> echo 'Bruce\'s test literal'; Bruce's test literal bruce_dev /> A string enclosed in double-quotes (") is subject to further processing. In addition to the handling of special characters using escape sequences any included variable names are expanded into a string representation of the value. This is a very powerful formatting tool. Strings may be concatenated using the period '.' operator. bruce_dev /> !="TEST"."ING"; TESTING bruce_dev /> ARRAYS Arrays are created using the array() function. These can be fully defined using the following construct. This takes any number of key => value pairs as arguments. array( key => value, key2 => value2, key3 => value3, ... ) BUILT-IN VARIABLES JANOS provides a small set of built-in variables. $_GET[ ] This array provides access to parameters supplied in the GET request URL. For example $_GET['name'] returns "INTEG" if ?name=INTEG is supplied in the URL. This would return NULL if it is not present. If a parameter appears in the URL without a value defined it is set to an empty string (""). When used from the Command Line the $_GET array enumerates the command line parameters following the command (either the batch file name or RUN command). $_POST[ ] This array provides access to parameters supplied as data in a POST request. HTML forms data may be submitted by either GET or POST methods. In the case of the latter the $_POST array provides access. $_SERVER[ ] This array provides access to parameters supplied by the Web Server. This includes the HTTP-Request headers. array $_SERVER { 'HTTP_GET' => string ('/test.php HTTP/1.1'), 'HTTP_HOST' => string ('bruce_dev'), 'HTTP_CONNECTION' => string ('keep-alive'), 'HTTP_UPGRADE_INSECURE_REQUESTS' => string ('1'), 'HTTP_USER_AGENT' => string ('Mozilla/5.0 (Windows NT 6.1; ... 'HTTP_ACCEPT' => string ('text/html,application/xhtml xml, ... 'HTTP_ACCEPT_ENCODING' => string ('gzip, deflate, sdch'), 'HTTP_ACCEPT_LANGUAGE' => string ('en-US,en;q=0.8'), 'HTTP_COOKIE' => string ('JANOS-Session-Id=6fe5fd609c4abb7f ... 'REQUEST_URL' => string ('/test.php'), 'SERVER_ROOT' => string ('/flash/public'), 'REQUEST_LOC' => string ('/'), 'DOC_SPEC' => string ('/flash/public/test.php'), 'DOC_NAME' => string ('test.php'), 'FILE_SPEC' => string ('/flash/public/test.php'), 'REMOTE_ADDR' => string (''), 'REMOTE_PORT' => string ('11099'), 'TLS_SECURED' => string ('FALSE') } NOTES You can escape a dollar sign '$' in a double-quoted string if necessary to avoid a variable expansion. This would be required to output currency amounts. While double-quoted strings can include variables in formatting the output string, The JANOS script engine also supports the printf() function providing access to C Language string formatting. This offers a much greater level of control over numeric formats for example. SEE ALSO HELP Topics: STATEMENTS, SCRIPT [/flash/manpages/program.hlp:356]