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…
http://www.bkjia.com/PHPjc/327740.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/327740.htmlTechArticlesmarty truncate 截取字串 從字串開始處截取某長度的字元,預設的長度為80 指定第二個參數作為截取字串的長度 預設情況下,smarty會截...