微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

runcate 截取字符串

从字符串开始处截取某长度的字符,认的长度为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…

原文地址:https://www.jb51.cc/php/26154.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐