PHP完全自学手册(珍藏版) 中文pdf扫描版下载
在smarty中截取字符串的函数是smarty的truncate。
用法如下:
truncate(a:b:c)
其中a,是截取的字符串长度,b是追加在截取字符串后面的文本字串.该追加字串被计算在截取长度中,,默认是“…”,c是想要精确的截取多少个字符,“false”截取到词的边界,“true”精确到字符,默认是false。
例如:
index.php:
$smarty = new Smarty;
$smarty->assign(‘articleTitle’, ‘Two Sisters Reunite after Eighteen Years at Checkout Counter.’);
$smarty->display(‘index.tpl’);
index.tpl:
{$articleTitle}
{$articleTitle|truncate}
{$articleTitle|truncate:30}
{$articleTitle|truncate:30:”"} //因为第三个参数是false,后卖弄的单词超出,所以到after截止。
{$articleTitle|truncate:30:”—”}
{$articleTitle|truncate:30:”":true} //完整的输出,到字符
{$articleTitle|truncate:30:”…”:true} //”…”占三个字符
输出结果:
Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after…
Two Sisters Reunite after
Two Sisters Reunite after—
Two Sisters Reunite after Eigh
Two Sisters Reunite after E…
转载请注明:谷谷点程序 » smarty的truncate