escape可用于将变量编码或转换成 html, url, 单引号, 十六进制, 十六进制实体,javascript 和 电邮地址。 默认是:html。

参数顺序类型必选参数允许取值默认值说明
1stringNohtml, htmlall, url, urlpathinfo, 单引号, 十六进制, 十六进制实体, javascript, 电邮地址html这是escape转换后的格式
2stringNoISO-8859-1, UTF-8, 和其他 htmlentities()支持的字符集UTF-8传递给htmlentities()的字符集类型
3booleanNoFALSETRUE两次转换实体,& 到 & (仅在 html 和 htmlall 使用)

escape例子
articleTitle:'Stiff Opposition Expected to Casketless Funeral Plan'
EmailAddress:smarty@example.com
下面是escape的例子和输出:

_{$articleTitle}_
输出:'Stiff Opposition Expected to Casketless Funeral Plan'

_{$articleTitle|escape}_
输出:'Stiff Opposition Expected to Casketless Funeral Plan'

_{$articleTitle|escape:'html'}_
输出:'Stiff Opposition Expected to Casketless Funeral Plan'


_{$articleTitle|escape:'htmlall'}_
输出:'Stiff Opposition Expected to Casketless Funeral Plan'

<a href="?title=_{$articleTitle|escape:'url'}_">click here</a>
输出:<a
href="?title=%27Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan%27">click here</a>

_{$articleTitle|escape:'quotes'}_
输出:\'Stiff Opposition Expected to Casketless Funeral Plan\'

<a href="mailto:_{$EmailAddress|escape:"hex"}_">_{$EmailAddress|escape:"hexentity"}_</a>
_{$EmailAddress|escape:'mail'}_
输出:<a href="mailto:%62%6f%..snip..%65%74">&#x62;&#x6f;&#x62..snip..&#x65;&#x74;</a>

_{'mail@example.com'|escape:'mail'}_
输出:smarty [AT] example [DOT] com