Smarty:truncate

2018-10-12 15:52 更新

truncate

截取字符串到指定長度,默認長度是80. 第二個參數可選,指定了截取后代替顯示的字符。 截取后的字符長度是截取規(guī)定的長度加上第二個參數的字符長度。 默認truncate會嘗試按單詞進行截取。 如果你希望按字符截?。▎卧~可能會被截斷),需要設置第三個參數TRUE。

參數順序類型必選參數默認值說明
1integerNo80截取的長度
2stringNo...截取后替代顯示的字符,該字符長度會被計算到截取長度內。
3booleanNoFALSE是否按單詞截取FALSE,或是按字符截取TRUE。
4booleanNoFALSE當字符截取的長度剛好等于字符本身長度時,是否截取。FALSE也會截取。 TRUE是不會截取。 注意如果設置為TRUE,單詞的邊界會被忽略。

Example 5.21. truncate

<?php
$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
?>

模板:

{$articleTitle}
{$articleTitle|truncate}
{$articleTitle|truncate:30}
{$articleTitle|truncate:30:""}
{$articleTitle|truncate:30:"---"}
{$articleTitle|truncate:30:"":true}
{$articleTitle|truncate:30:"...":true}
{$articleTitle|truncate:30:'..':true: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...
Two Sisters Re..ckout Counter.

以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號