escape
转码

Parameter PositionTypeRequiredPossible ValuesDefaultDescription
1stringNohtml,htmlall,url,quotes,hex,hexentity,javascripthtmlThis is the escape format to use.

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.

用于html转码,url转码,在没有转码的变量上转换单引号,十六进制转码,十六进制美化,或者javascript转码.
默认是html转码

Example 5-11. escape
例 5-11.转码

index.php:



$smarty = new Smarty;

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

$smarty->display('index.tpl');



index.tpl:



{$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>



OUTPUT:



'Stiff Opposition Expected to Casketless Funeral Plan'

'Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan'

'Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan'

'Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan'

'Stiff+Opposition+Expected+to+Casketless+Funeral+Plan'

\'Stiff Opposition Expected to Casketless Funeral Plan\'

<a

href="mailto:%62%6f%62%40%6d%65%2e%6e%65%74">&#x62;&#x6f;&#x62;&#x40;&#x6d;&#x65;&#x2e;&#x6e;&#x65;&#x74;</a>





Stiff Opposition Expected to Casketless Funeral Plan Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan Stiff+Opposition+Expected+to+Casketless+Funeral+Plan \'Stiff Opposition Expected to Casketless Funeral Plan\' bob@me.net