Get Smarty


Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap glasses from and save up to 80%.

Where to buy prescription glasses? is your best choice!

Where to buy discount wedding dresses and cheap smart dresses free shipping -

Shop for 2018 World Cup Football Boots Online sale at

Browse best 2018 world cup soccer cleats and shoes from



截取字符串到指定长度,默认长度是80. 第二个参数可选,指定了截取后代替显示的字符。 截取后的字符长度是截取规定的长度加上第二个参数的字符长度。 默认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

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






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.


No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Email: (not shown)
What is 19 plus 11? (Are you human?)