PHP项目SmartySmarty截取字符串方法truncate
Posted 欧小羊
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP项目SmartySmarty截取字符串方法truncate相关的知识,希望对你有一定的参考价值。
smarty truncate 截取字符串 //在sql中truncate是删除表格(truncate是只删除内容,delete彻底删除)
从字符串开始处截取某长度的字符,默认的长度为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…
以上是关于PHP项目SmartySmarty截取字符串方法truncate的主要内容,如果未能解决你的问题,请参考以下文章