smarty truncate 截取字符串长度

smarty truncate 截取
從字符串开始处截取某长度的字符.默认是80個。
你也可以指定第二個参数作为追加在截取字符串后面的文本字串.该追加字串被计算在截取长度中。
默认情況下,smarty会截取到一个词的末尾。
如果你想要精確的截取多少個字符,把第三個参数改为"true" 。


例 截取:

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:""}
{$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...

文章如转载,请注明:转载自:第九街-PHP[http://www.9streets.cn/]
本文链接地址:
发布者:9streets于 2009-11-24 发表 | 我要评论(1) | 阅读次数(4324)

转播到腾讯微博

上一篇: smarty教程

首页第九街博客由来关于博主联系博主免责条款隐私保护九街项目流程 | 网站地图 | 申请友情链接