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

smarty truncate 截取字符串
从字符串开始处截取某长度的字符,默认的长度为80
指定第二个参数作为截取字符串的长度
默认情况下,smarty会截取到一个词的末尾,
如果需要精确到截取多少个字符可以使用第三个参数,将其设为”true”
具体用法如下:

复制代码代码如下:

//index.php $smarty = new Smarty; 
$smarty->assign('supportTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.'); 
$smarty->display('index.tpl'); 
//index.tpl 
{$supportTitle} 
{$supportTitle|truncate} 
{$supportTitle|truncate:30} 
{$supportTitle|truncate:30:""} 
{$supportTitle|truncate:30:"---"} 
{$supportTitle|truncate:30:"":true}
{$supportTitle|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…

餐厅介绍

自助餐厅

4.7分
537m | 中航城区冷死你境内呢名
停车 WiFi
  • 热情1
  • 环境好11
  • 服务好12
  • 好极了31
  • 服务热情14

暂时没有看法.. 发表看法请遵守当地法律和制度 (网友评论仅供其表达个人看法,并不表明本站立场。)