4 smarty
我想用smarty编码一个url.
<a href="https://www.facebook.com/sharer/sharer.php?u={$var} " target="_blank"></a>
Run Code Online (Sandbox Code Playgroud)
$ var包含我的数据网址
And*_*olk 13
使用escape修饰符,您可以设置可选的escape_type'url'以返回rawurlencode().
{$var|escape:'url'}
Run Code Online (Sandbox Code Playgroud)
默认情况下,{$ var | escape}使用escape_type'html'并返回htmlspecialchars(),其中'&'(&符号)变为&.所以'url'可能有用.rawurlencode()保护文字字符不被解释为特殊的URL分隔符:
<a href="https://www.facebook.com/sharer/sharer.php?u={$var|escape:'url'} " target="_blank"></a>
Run Code Online (Sandbox Code Playgroud)
您可以使用转义修饰符
{$var|escape}
Run Code Online (Sandbox Code Playgroud)
更多信息请访问: http://www.smarty.net/docsv2/en/language.modifier.escape.tpl