Text->truncate方法有3個參數(shù):
$text:需要截取的字符串
$length:需要截取的長度,默認是截取100個字符
$options:數(shù)組參數(shù),ending表示在截取后的字符串結(jié)尾加上ending字符串,exact如果是false的話則不會截斷word,html如果是true的話則不會截斷html tag.
下面的代碼演示了如何使用tuncate方法:
- echo $this->Text->truncate(
- 'The killer crept forward and tripped on the rug.', 22,
- array(
- 'ending' => '...',
- 'exact' => false
- )
- );
- //上面的代碼將輸出The killer crept…
注意:如果是截取中文字符串的話exact最好置為true,否則漢語字符將無法被截斷.
新聞熱點
疑難解答