smarty中的修饰函数:
对在模板文件中显示的数据变量进行二次修饰。
格式:
{ts:变量|函数名:参数1:参数2:参数3...|函数名:参数1:参数2...}
常见的修饰函数:
capitalize:首字母大写
count_characters:统计字符数
count_words():统计单词数
date_format:日期设置
default:默认值
indent:缩进
lower:小写
upper:大写
nl2br:将换行符转换成br
replace:字符串替换
strip_tags:去掉html代码标签
truncate:字符串截取
【modify.php】
<?php
require_once("./smarty.inc.php");
$str = "this is my page";
$time = time();
$nl2br = "that \nis cat."; //将换行符转换成br
$html = "<h1>this is strip_tags</h1>";
$tpl -> assign("str",$str);
$tpl -> assign("time",$time);
$tpl -> assign("nl2br",$nl2br);
$tpl -> assign("html",$html);
$tpl -> display("modify.html");
?>
【modify.html】
{ts:$str}<br/>
capitalize:{ts:$str|capitalize}
<hr/>
{ts:$str}<br/>
count_characters:{ts:$str|count_characters:true}
<hr/>
{ts:$str}<br/>
count_words:{ts:$str|count_words}
<hr/>
{ts:$time}<br/>
date_format:{ts:$time|date_format:"Y-m-d"}
<hr/>
{ts:$smarty.session.username}<br/>
default:{ts:$smarty.session.username|default:"<a href=''>登录/注册</a>"}
<hr/>
{ts:$str}<br/>
{ts:$str|indent:10}
<hr/>
{ts:$str}<br/>
{ts:$str|upper|lower}
<hr/>
{ts:$nl2br}<br/>
{ts:$nl2br|nl2br}
<hr/>
{ts:$str}<br/>
{ts:$str|replace:"i":"*"}
<hr/>
{ts:$html}<br/>
{ts:$html|strip_tags}
<hr/>
{ts:$str}<br/>
{ts:$str|truncate:10:""}
<hr/>
<hr/>
#在modify.php中获取前台modify.html中的值#