| Zeile 1... |
Zeile -... |
| 1 |
escape {#language.modifier.escape}
|
- |
|
| 2 |
======
|
1 |
# escape
|
| Zeile 3... |
Zeile 2... |
| 3 |
|
2 |
|
| 4 |
`escape` is used to encode or escape a variable to `html`, `url`,
|
3 |
`escape` is used to encode or escape a variable to `html`, `url`,
|
| 5 |
`single quotes`, `hex`, `hexentity`, `javascript` and `mail`. By default
|
4 |
`single quotes`, `hex`, `hexentity`, `javascript` and `mail`. By default
|
| Zeile 6... |
Zeile -... |
| 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.
|
- |
|
| - |
|
5 |
its `html`.
|
| - |
|
6 |
|
| - |
|
7 |
## Basic usage
|
| - |
|
8 |
```smarty
|
| Zeile -... |
Zeile 9... |
| - |
|
9 |
{$myVar|escape}
|
| Zeile 11... |
Zeile -... |
| 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.
|
- |
|
| - |
|
10 |
```
|
| - |
|
11 |
|
| - |
|
12 |
## Parameters
|
| - |
|
13 |
|
| - |
|
14 |
| Parameter Position | Type | Required | Possible Values | Default | Description |
|
| Zeile 12... |
Zeile -... |
| 12 |
3 boolean No FALSE TRUE Double encode entites from & to & (applys to `html` and `htmlall` only)
|
- |
|
| 13 |
|
- |
|
| 14 |
|
- |
|
| 15 |
<?php
|
- |
|
| Zeile 16... |
Zeile 15... |
| 16 |
|
15 |
|--------------------|---------|----------|----------------------------------------------------------------------------------------------------------------|---------|--------------------------------------------------------------------------------------|
|
| Zeile -... |
Zeile 16... |
| - |
|
16 |
| 1 | string | No | `html`, `htmlall`, `url`, `urlpathinfo`, `quotes`, `hex`, `hexentity`, `javascript`, `mail` | `html` | This is the escape format to use. |
|
| 17 |
$smarty->assign('articleTitle',
|
17 |
| 2 | string | No | `ISO-8859-1`, `UTF-8`, and any character set supported by [`htmlentities()`](https://www.php.net/htmlentities) | `UTF-8` | The character set encoding passed to htmlentities() et. al. |
|
| Zeile -... |
Zeile 18... |
| - |
|
18 |
| 3 | boolean | No | FALSE | TRUE | Double encode entities from & to &amp; (applies to `html` and `htmlall` only) |
|
| 18 |
"'Stiff Opposition Expected to Casketless Funeral Plan'"
|
19 |
|
| - |
|
20 |
|
| - |
|
21 |
## Examples
|
| Zeile -... |
Zeile 22... |
| - |
|
22 |
|
| - |
|
23 |
```php
|
| Zeile 19... |
Zeile -... |
| 19 |
);
|
- |
|
| 20 |
$smarty->assign('EmailAddress','smarty@example.com');
|
24 |
<?php
|
| Zeile -... |
Zeile 25... |
| - |
|
25 |
|
| 21 |
|
26 |
$smarty->assign('articleTitle',
|
| 22 |
?>
|
27 |
"'Stiff Opposition Expected to Casketless Funeral Plan'"
|
| Zeile 23... |
Zeile 28... |
| 23 |
|
28 |
);
|
| 24 |
|
29 |
$smarty->assign('EmailAddress','smarty@example.com');
|
| Zeile 25... |
Zeile 30... |
| 25 |
|
30 |
|
| 26 |
These are example `escape` template lines followed by the output
|
31 |
```
|
| Zeile 27... |
Zeile 32... |
| 27 |
|
32 |
|
| 28 |
|
- |
|
| 29 |
{$articleTitle}
|
33 |
|
| Zeile 30... |
Zeile 34... |
| 30 |
'Stiff Opposition Expected to Casketless Funeral Plan'
|
34 |
These are example `escape` template lines followed by the output
|
| - |
|
35 |
|
| 31 |
|
36 |
```smarty
|
| Zeile 32... |
Zeile 37... |
| 32 |
{$articleTitle|escape}
|
37 |
{$articleTitle}
|
| 33 |
'Stiff Opposition Expected to Casketless Funeral Plan'
|
38 |
'Stiff Opposition Expected to Casketless Funeral Plan'
|
| 34 |
|
- |
|
| Zeile 35... |
Zeile 39... |
| 35 |
{$articleTitle|escape:'html'} {* escapes & " ' < > *}
|
39 |
|
| 36 |
'Stiff Opposition Expected to Casketless Funeral Plan'
|
40 |
{$articleTitle|escape}
|
| - |
|
41 |
'Stiff Opposition Expected to Casketless Funeral Plan'
|
| Zeile 37... |
Zeile -... |
| 37 |
|
- |
|
| - |
|
42 |
|
| - |
|
43 |
{$articleTitle|escape:'html'} {* escapes & " ' < > *}
|
| Zeile -... |
Zeile 44... |
| - |
|
44 |
'Stiff Opposition Expected to Casketless Funeral Plan'
|
| - |
|
45 |
|
| Zeile 38... |
Zeile -... |
| 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>
|
46 |
{$articleTitle|escape:'htmlall'} {* escapes ALL html entities *}
|
| Zeile 42... |
Zeile 47... |
| 42 |
<a
|
47 |
'Stiff Opposition Expected to Casketless Funeral Plan'
|
| 43 |
href="?title=%27Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan%27">click here</a>
|
48 |
|
| 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 *}
|
- |
|
| Zeile -... |
Zeile 49... |
| - |
|
49 |
<a href="?title={$articleTitle|escape:'url'}">click here</a>
|
| - |
|
50 |
<a
|
| - |
|
51 |
href="?title=%27Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan%27">click here</a>
|
| - |
|
52 |
|
| - |
|
53 |
{$articleTitle|escape:'quotes'}
|
| 50 |
<a href="mailto:%62%6f%..snip..%65%74">bob..snip..et</a>
|
54 |
\'Stiff Opposition Expected to Casketless Funeral Plan\'
|
| 51 |
|
55 |
|
| 52 |
{'mail@example.com'|escape:'mail'}
|
56 |
<a href="mailto:{$EmailAddress|escape:"hex"}">{$EmailAddress|escape:"hexentity"}</a>
|