Smarty字符串截取函数:truncate

blogdaren 2014-12-14 抢沙发 1667人次

truncate函数说明:

1、第一个参数代表要截取的字符串的长度,默认为80个。
2、第二个参数代表追加在截取字符串后面的文本字串,该追加字串被计算在截取长度中。

3、默认情況下,函数会一直截取到字符串的末尾,如果想要精确的截取固定长度字符,请把第三个参数置为 true。

举例说明:

index.php:
<?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...

版权声明:除非注明,本文由( blogdaren )原创,转载请保留文章出处。

本文链接:Smarty字符串截取函数:truncate

发表评论:

您的昵称:
电子邮件:
个人主页:

Free Web Hosting