|
從字符串開始處截取某長(zhǎng)度的字符,默認(rèn)的長(zhǎng)度為80
指定第二個(gè)參數(shù)作為截取字符串的長(zhǎng)度
默認(rèn)情況下,smarty會(huì)截取到一個(gè)詞的末尾,
如果需要精確到截取多少個(gè)字符可以使用第三個(gè)參數(shù),將其設(shè)為”true”
具體用法如下:
復(fù)制代碼 代碼如下:
//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}
輸出結(jié)果:
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技術(shù):解析smarty 截取字符串函數(shù) truncate的用法介紹,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。