escape

escape

This is used to html escape, url escape, escape single quotes on a variable not already escaped, hex escape, hexentity or javascript escape. By default, the variable is html escaped.

Parameter PositionTypeRequiredPossible ValuesDefaultDescription
1stringNohtml,htmlall,url,urlpathinfo,quotes,hex,hexentity,javascripthtmlThis is the escape format to use.
2stringNoISO-8859-1, UTF-8, ... any character set supportet by htmlentities() ISO-8859-1The character set encoding passed to htmlentities() et. al.

Example 5-10. escape

<?php
    
$smarty
->assign('articleTitle',
                
"'Stiff Opposition Expected to Casketless Funeral Plan'"
                
);
    
?>

Where template is:

{$articleTitle}
{$articleTitle|escape}
{$articleTitle|escape:"html"}    {* escapes  & " ' < > *}
{$articleTitle|escape:"htmlall"} {* escapes ALL html entities *}
{$articleTitle|escape:"url"}
{$articleTitle|escape:"quotes"}
<a href="mailto:{$EmailAddress|escape:"hex"}">{$EmailAddress|escape:"hexentity"}</a>

This will output:

'Stiff Opposition Expected to Casketless Funeral Plan'
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;
%27Stiff+Opposition+Expected+to+Casketless+Funeral+Plan%27
\'Stiff Opposition Expected to Casketless Funeral Plan\'
<a href="mailto:%62%6f%..snip..%65%74">&#x62;&#x6f;&#x62..snip..&#x65;&#x74;</a>

See also Escaping Smarty Parsing and Obfuscating E-mail Addresses.

© Copyright 2003-2023 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.