W3Cschool
恭喜您成為首批注冊用戶
獲得88經驗值獎勵
截取字符串到指定長度,默認長度是80. 第二個參數可選,指定了截取后代替顯示的字符。 截取后的字符長度是截取規(guī)定的長度加上第二個參數的字符長度。 默認truncate
會嘗試按單詞進行截取。 如果你希望按字符截?。▎卧~可能會被截斷),需要設置第三個參數TRUE
。
參數順序 | 類型 | 必選參數 | 默認值 | 說明 |
---|---|---|---|---|
1 | integer | No | 80 | 截取的長度 |
2 | string | No | ... | 截取后替代顯示的字符,該字符長度會被計算到截取長度內。 |
3 | boolean | No | FALSE | 是否按單詞截取FALSE ,或是按字符截取TRUE 。 |
4 | boolean | No | FALSE | 當字符截取的長度剛好等于字符本身長度時,是否截取。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.
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯系方式:
更多建議: