Escape

escape — is used to encode or escape a variable to html, url, single quotes, hex, hexentity, javascript and mail. By default its html.

  • value: the string to process
  • format: escaping format to use, valid formats are : html, htmlall, url, urlpathinfo, quotes, hex, hexentity, javascript and mail
  • charset: character set to use for the conversion (applies to some formats only), defaults to the current Tplix charset
  • Available formats:
  • html
  • htmlall
  • url
  • urlpathinfo
  • quotes
  • hex
  • hexentity
  • javascript
  • js
  • mail
Examples:

Where template is:

{$myVar|escape}

<?php
$tplix->assign('articleTitle',
      			"'Stiff Opposition Expected to Casketless Funeral Plan'"
                );
$tplix->assign('EmailAddress','tplix@example.com');    
    

These are example escape template lines followed by the output


{$articleTitle}
'Stiff Opposition Expected to Casketless Funeral Plan'

{$articleTitle|escape}
'Stiff Opposition Expected to Casketless Funeral Plan'

{$articleTitle|escape:'html'}    {* escapes  & " ' < > *}
'Stiff Opposition Expected to Casketless Funeral Plan'

{$articleTitle|escape:'htmlall'} {* escapes ALL html entities *}
'Stiff Opposition Expected to Casketless Funeral Plan'

<a href="?title={$articleTitle|escape:'url'}">click here</a>
<a
href="?title=%27Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan%27">click here</a>

{$articleTitle|escape:'quotes'}
\'Stiff Opposition Expected to Casketless Funeral Plan\'

<a href="mailto:{$EmailAddress|escape:"hex"}">{$EmailAddress|escape:"hexentity"}</a>
{$EmailAddress|escape:'mail'}    {* this converts to email to text *}
<a href="mailto:%62%6f%..snip..%65%74">bob..snip..et</a>

{'mail@example.com'|escape:'mail'}
tplix [AT] example [DOT] com

{* the "rewind" parameter registers the current location *}
<a href="$my_path?page=foo&rewind={$my_uri|escape:url}">click here</a>    
    
Was this article helpful?