codecamp

Smarty:escape

escape

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

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

Example 5.10. escape

<?php

$smarty->assign('articleTitle',
                "'Stiff Opposition Expected to Casketless Funeral Plan'"
                );
$smarty->assign('EmailAddress','smarty@example.com');

?>

下面是escape的例子和输出:

{$articleTitle}
'Stiff Opposition Expected to Casketless Funeral Plan'

{$articleTitle|escape}
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;

{$articleTitle|escape:'html'}    {* escapes  & " ' < > *}
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;

{$articleTitle|escape:'htmlall'} {* escapes ALL html entities *}
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;

<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'}    {* this converts to email to text *}
<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

Example 5.11. escape的另一个例子

{*  "rewind"参数是当前URL地址 *}
<a href="$my_path?page=foo&rewind=$my_uri|urlencode}">click here</a>

这个方法很适合用在电邮地址上,另外可以参见 {mailto}

{* 电邮地址编码 *}
<a href="mailto:{$EmailAddress|escape:'hex'}">{$EmailAddress|escape:'mail'}</a>

参见 Smarty编译转换, {mailto} 和 混淆电邮地址。

Smarty:default
Smarty:from_charset
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

I.Smarty基础

1.Smart是什么?

II.Smarty模板设计师篇

6.Smarty复合修饰器

9.Smarty配置文件

10.Smarty调试控制台

III. 程序开发者篇

11. Smarty字符集编码

12.Smarty常量

13.Smarty成员变量

14.Smarty成员方法

17.Smarty高级特性

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }