精彩推荐

smarty截取字符串函数truncate的用法介绍

828人阅读  0人回复   查看全部 | 阅读模式 | 复制链接   

3

主题

3

帖子

13

积分

新手上路

Rank: 1

积分
13
发表于 2015-3-31 16:28:04
本篇文章是对smarty 截取字符串函数 truncate的用法进行了详细的分析介绍,需要的朋友参考下
smarty truncate 截取字符串
从字符串开始处截取某长度的字符,默认的长度为80
指定第二个参数作为截取字符串的长度
默认情况下,smarty会截取到一个词的末尾,
如果需要精确到截取多少个字符可以使用第三个参数,将其设为”true”
具体用法如下:
  1. //index.php $smarty = new Smarty;
  2. $smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
  3. $smarty->display('index.tpl');
  4. //index.tpl
  5. {$articleTitle}
  6. {$articleTitle|truncate}
  7. {$articleTitle|truncate:30}
  8. {$articleTitle|truncate:30:""}
  9. {$articleTitle|truncate:30:"---"}
  10. {$articleTitle|truncate:30:"":true}
  11. {$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…
回复

使用道具 举报

快速回复 返回顶部 返回列表