escape {#language.modifier.escape}
======
`escape` is used to encode or escape a variable to `html`, `url`,
`single quotes`, `hex`, `hexentity`, `javascript` and `mail`. By default
its `html`.
Parameter Position Type Required Possible Values Default Description
-------------------- --------- ---------- ------------------------------------------------------------------------------------------------------------ --------- -------------------------------------------------------------------------------------
1 string No `html`, `htmlall`, `url`, `urlpathinfo`, `quotes`, `hex`, `hexentity`, `javascript`, `mail` `html` This is the escape format to use.
2 string No `ISO-8859-1`, `UTF-8`, and any character set supported by [`htmlentities()`](&url.php-manual;htmlentities) `UTF-8` The character set encoding passed to htmlentities() et. al.
3 boolean No FALSE TRUE Double encode entites from & to & (applys to `html` and `htmlall` only)
assign('articleTitle',
"'Stiff Opposition Expected to Casketless Funeral Plan'"
);
$smarty->assign('EmailAddress','smarty@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'
click here
click here
{$articleTitle|escape:'quotes'}
\'Stiff Opposition Expected to Casketless Funeral Plan\'
{$EmailAddress|escape:"hexentity"}
{$EmailAddress|escape:'mail'} {* this converts to email to text *}
bob..snip..et
{'mail@example.com'|escape:'mail'}
smarty [AT] example [DOT] com
{* the "rewind" parameter registers the current location *}
click here
This snippet is useful for emails, but see also
[`{mailto}`](#language.function.mailto)
{* email address mangled *}
{$EmailAddress|escape:'mail'}
See also [escaping smarty parsing](#language.escaping),
[`{mailto}`](#language.function.mailto) and the [obfuscating email
addresses](#tips.obfuscating.email) page.