Variable Naming & Syntax

Variable names:

are case-sensitive; NOTE: This is a change from v11.0 and prior where variable names were case-insensitive.

must begin with an alphabetic character or an underscore (low line) character; NOTE: The underscore character is only allowed in v11.9910 or higher.

must consist only of alphanumeric characters or the underscore (low line) character

To access a variable, use $var for a string variable or #var for an integer variable, though these can often be interchanged, especially in v11.9910 or above.

Setting variables within integer and string expressions is possible.

Assigning a String Value

$name=string exp;

Creates a variable called $name (if it doesn't already exist), and sets its value to the specified string expression.

Examples: $name="Jane Doe"; or $name="Jane"+"Doe";

Single quotes are also allowed. Examples: $name='Jane Doe'; or $name='Jane'+'Doe';

Assigning an Integer Value

$sum=int exp;

Creates a variable called $sum (if it doesn't already exist), and sets its value to the specified integer expression.

Examples: $sum=20; or $sum=10+5+5;

NOTE: Integer variables in versions prior to CSE HTML Validator v12 generally required the '#' symbol instead of the '$' symbol.

Compound Assignments

TNPL supports compound assignment operators in CSE HTML Validator v12 and above: += for addition, -= for subtraction, *= for multiplication, /= for division, %= for modulo, &= for bitwise AND, |= for bitwise OR, ^= for bitwise XOR (exclusive or), <<= for bitwise left shift, and >>= for bitwise right shift.

Example: $a+=$b is the same as $a=$a+$b

Variable 'Functions'

The following 'variable functions' may be used in CSE HTML Validator v12 and above when referencing a variable, like $var. Using these functions may result in faster and easier to read code.

In CSE HTML Validator v14, these 'variable functions' can now be used after almost any value, not just variable references.

$var.arrayLength() - returns the number of elements (0 or more) in the $var array, or 0 if $var is not an array; see also $var.lastIndex()

$var.containsCollapsed() - (VALIDATOR ENGINE ONLY) returns 1 if $var contains any collapsed PHP, ASP, etc. code. (looks for strings like "!PHP!", "!ASP!", and "!MIVA!") (New v14.00)

$var.insert(string $s) - inserts the string $s into $var (if not already there); $var must be a set of strings (New v12.0106)

$var.hasValue(string $str1[, string $str2...]) - returns the index (1 or greater) of the first matching string if $var is an array or string set and contains at least one of the given strings $strx (case-sensitive unless $var is set of strings that is not case-sensitive) (New v12.0106)

NOTE: In versions prior to v16.00, this function only accepted one string parameter and only returned 0 or 1.

$var.hasValueNoCase(string $str1[, string $str2...]) - returns the index (1 or greater) of the first matching string if $var is an array or string set and it contains at least one of given strings $strx (case-insensitive), else returns 0 (New v14.00)

NOTE: In versions prior to v16.00, this function only accepted one string parameter and only returned 0 or 1.

$var.isArray() - returns 1 if $var is an array, else 0

$var.isEmpty() - returns 1 if $var is a string and is empty (equal to ""), or an array with no elements or an integer equal to 0, else returns 0

$var.isEmpty2() - returns 1 if $var is a string and is empty (equal to "") or contains only whitespace or the non-breaking space (&nbsp;) characters, or an array with no elements or an integer equal to 0, else returns 0 (New v14.00)

$var.isInt() - returns 1 if $var represents an integer value (as opposed to a string or an array, even if the string can be converted to an integer), else 0

$var.isNotEmpty() - returns the opposite of $var.isEmpty()

$var.isNotSet() - returns 1 if $var is undefined, else 0 (New v14.00)

$var.isSet() - returns 1 if $var has a value (it's not undefined), else 0 (New v12.0024)

$var.isString() - returns 1 if $var represents a string (as opposed to an integer or an array), else 0

$var.isZero() - returns 1 if $var is an integer or float equal to 0, or a string containing only one or more zeroes, else returns 0 (New v12.0033)

$var.lastIndex() - returns the last numeric index of the $var array, or -1 if $var is an empty array or not an array; equivalent to $var.arrayLength()-1 (New v16.0000)

$var.ltrim() - performs an ltrim() on $var (New v12.0024)

$var.reset() - performs an unset() on $var; same as unset() (New v14.00)

$var.resetArray() - sets $var to an empty array (New v14.00)

$var.resetInt() - sets $var to the integer 0 like $var=0 but a little faster (New v12.0027)

$var.resetString() - sets $var to an empty string like $var='' but a little faster (New v12.0027)

$var.resetStringSetCase() - sets $var to an unordered set of strings that is case-sensitive (New v12.0106)

$var.resetStringSetNoCase() - sets $var to an unordered set of strings that is case-insensitive (New v12.0106)

$var.rtrim() - performs an rtrim() on $var (New v12.0024)

$var.setToVar($var2) - quick (high performance) way to set a variable ($var) to another variable ($var2); MUST set only to a variable because $var.setToVar("hello") is invalid (new v12.0027)

$var.stringLength() - returns the length of the string (0 or more) if $var is a string, or 0 if $var is not a string

$var.toFloat() - converts $var to a floating point number (New v12.0030)

$var.toInt() - converts $var to an integer (New v14.0101)

$var.toLower() - performs a toLower() on $var (New v12.0024)

$var.toUpper() - performs a toUpper() on $var (New v12.0024)

$var.trim() - performs a trim() on $var (New v12.0024)

$var.unset() - performs an unset() on $var; same as reset() (New v12.0024)