| 148 |
lars |
1 |
escape {#language.modifier.escape}
|
|
|
2 |
======
|
|
|
3 |
|
|
|
4 |
`escape` is used to encode or escape a variable to `html`, `url`,
|
|
|
5 |
`single quotes`, `hex`, `hexentity`, `javascript` and `mail`. By default
|
|
|
6 |
its `html`.
|
|
|
7 |
|
|
|
8 |
Parameter Position Type Required Possible Values Default Description
|
|
|
9 |
-------------------- --------- ---------- ------------------------------------------------------------------------------------------------------------ --------- -------------------------------------------------------------------------------------
|
|
|
10 |
1 string No `html`, `htmlall`, `url`, `urlpathinfo`, `quotes`, `hex`, `hexentity`, `javascript`, `mail` `html` This is the escape format to use.
|
|
|
11 |
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.
|
|
|
12 |
3 boolean No FALSE TRUE Double encode entites from & to & (applys to `html` and `htmlall` only)
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
<?php
|
|
|
16 |
|
|
|
17 |
$smarty->assign('articleTitle',
|
|
|
18 |
"'Stiff Opposition Expected to Casketless Funeral Plan'"
|
|
|
19 |
);
|
|
|
20 |
$smarty->assign('EmailAddress','smarty@example.com');
|
|
|
21 |
|
|
|
22 |
?>
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
These are example `escape` template lines followed by the output
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
{$articleTitle}
|
|
|
30 |
'Stiff Opposition Expected to Casketless Funeral Plan'
|
|
|
31 |
|
|
|
32 |
{$articleTitle|escape}
|
|
|
33 |
'Stiff Opposition Expected to Casketless Funeral Plan'
|
|
|
34 |
|
|
|
35 |
{$articleTitle|escape:'html'} {* escapes & " ' < > *}
|
|
|
36 |
'Stiff Opposition Expected to Casketless Funeral Plan'
|
|
|
37 |
|
|
|
38 |
{$articleTitle|escape:'htmlall'} {* escapes ALL html entities *}
|
|
|
39 |
'Stiff Opposition Expected to Casketless Funeral Plan'
|
|
|
40 |
|
|
|
41 |
<a href="?title={$articleTitle|escape:'url'}">click here</a>
|
|
|
42 |
<a
|
|
|
43 |
href="?title=%27Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan%27">click here</a>
|
|
|
44 |
|
|
|
45 |
{$articleTitle|escape:'quotes'}
|
|
|
46 |
\'Stiff Opposition Expected to Casketless Funeral Plan\'
|
|
|
47 |
|
|
|
48 |
<a href="mailto:{$EmailAddress|escape:"hex"}">{$EmailAddress|escape:"hexentity"}</a>
|
|
|
49 |
{$EmailAddress|escape:'mail'} {* this converts to email to text *}
|
|
|
50 |
<a href="mailto:%62%6f%..snip..%65%74">bob..snip..et</a>
|
|
|
51 |
|
|
|
52 |
{'mail@example.com'|escape:'mail'}
|
|
|
53 |
smarty [AT] example [DOT] com
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
{* the "rewind" parameter registers the current location *}
|
|
|
59 |
<a href="$my_path?page=foo&rewind=$my_uri|urlencode}">click here</a>
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
This snippet is useful for emails, but see also
|
|
|
64 |
[`{mailto}`](#language.function.mailto)
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
{* email address mangled *}
|
|
|
68 |
<a href="mailto:{$EmailAddress|escape:'hex'}">{$EmailAddress|escape:'mail'}</a>
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
See also [escaping smarty parsing](#language.escaping),
|
|
|
73 |
[`{mailto}`](#language.function.mailto) and the [obfuscating email
|
|
|
74 |
addresses](#tips.obfuscating.email) page.
|