php:HTMLSpecialChar
smarty 用 escape
{$articleTitle|escape}
{$articleTitle|escape:"html"} {* escapes & " ' < > *}
{$articleTitle|escape:"htmlall"} {* escapes ALL html entities *}
{$articleTitle|escape:"url"}
{$articleTitle|escape:"quotes"}
<a href="mailto:{$EmailAddress|escape:"hex"}">{$EmailAddress|escape:"hexentity"}</a>
上面是处理代码转义的
下面这个是处理 换行的
PHP nl2br()
smarty
{{$content|nl2br}}
整个合起来是
{{$content|escape:"html"|nl2br}}
smarty 用 escape
{$articleTitle|escape}
{$articleTitle|escape:"html"} {* escapes & " ' < > *}
{$articleTitle|escape:"htmlall"} {* escapes ALL html entities *}
{$articleTitle|escape:"url"}
{$articleTitle|escape:"quotes"}
<a href="mailto:{$EmailAddress|escape:"hex"}">{$EmailAddress|escape:"hexentity"}</a>
上面是处理代码转义的
下面这个是处理 换行的
PHP nl2br()
smarty
{{$content|nl2br}}
整个合起来是
{{$content|escape:"html"|nl2br}}

本文介绍了使用Smarty模板引擎处理字符串的方法,包括如何利用escape函数进行HTML、URL等类型的转义,以及如何使用nl2br函数处理文本中的换行符。通过组合使用这两个函数可以有效地在网页中展示包含特殊字符和换行的文本内容。
6266

被折叠的 条评论
为什么被折叠?



