Escaped echo

The ? instruction not only replaces echo, but also provides escaping of reserved symbols. All the XML elements and attributes with its angled brackets and other symbols are output by specific instructions. The ? instruction takes the arguments to be echoed and either escapes them at pre-compile time if they are literals or calls the PHP htmlentities() function if they are expressions.  The same function is used for the values of attributes, which should be equally escaped.

Thus, this:

? 'This is a literal with some troublesome characters: &, <, >';
? $something;
<StartTag {
	&att1 'more reserved symbols: "<>&';
	&att2 $somethingelse;
}

will be converted into this:

echo 'This is a literal with some troublesome characters: &amp;, &lt;, &gt;';
echo htmlentities($something);
echo '<StartTag att1="more reserved symbols: &quot;&lt;&gt;&amp;" att2="' , htmlentities($somethingelse), '"/>";

So, if the argument can be escaped at compile time, it will be, otherwise it will be escaped at execution time.

< Previous: Modifying the tree

Up

Next: Compatcing echos >