欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-12-28 08:52:53
smarty truncate 截取字符串从字符串开始处截取某长度的字符,默认的长度为80指定第二个参数作为截取字符串的长度默认情况下,smarty会截取到一个词的末尾,如...
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…