解析smarty 截取字符串函數(shù) truncate的用法介紹
更新時間:2013年06月20日 12:01:32 作者:
本篇文章是對smarty 截取字符串函數(shù) truncate的用法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
smarty truncate 截取字符串
從字符串開始處截取某長度的字符,默認(rèn)的長度為80
指定第二個參數(shù)作為截取字符串的長度
默認(rèn)情況下,smarty會截取到一個詞的末尾,
如果需要精確到截取多少個字符可以使用第三個參數(shù),將其設(shè)為”true”
具體用法如下:
//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…
從字符串開始處截取某長度的字符,默認(rèn)的長度為80
指定第二個參數(shù)作為截取字符串的長度
默認(rèn)情況下,smarty會截取到一個詞的末尾,
如果需要精確到截取多少個字符可以使用第三個參數(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…
相關(guān)文章
詳解WordPress開發(fā)中wp_title()函數(shù)的用法
這篇文章主要介紹了WordPress開發(fā)中wp_title()函數(shù)的用法,wp_title可以用來顯示文章標(biāo)題和分類名稱等,需要的朋友可以參考下2016-01-01php實現(xiàn)36進(jìn)制與10進(jìn)制轉(zhuǎn)換功能示例
這篇文章主要介紹了php實現(xiàn)36進(jìn)制與10進(jìn)制轉(zhuǎn)換功能,結(jié)合實例形式分析了php數(shù)值運算與字符串操作的相關(guān)技巧,需要的朋友可以參考下2017-01-01php 隨機(jī)數(shù)的產(chǎn)生、頁面跳轉(zhuǎn)、件讀寫、文件重命名、switch語句
剛做的一個項目中的部分代碼,包含了php中隨機(jī)數(shù)的產(chǎn)生、頁面跳轉(zhuǎn)、件讀寫、文件重命名、switch語句。2009-08-08php實現(xiàn)數(shù)組中索引關(guān)聯(lián)數(shù)據(jù)轉(zhuǎn)換成json對象的方法
這篇文章主要介紹了php實現(xiàn)數(shù)組中索引關(guān)聯(lián)數(shù)據(jù)轉(zhuǎn)換成json對象的方法,基于Yii框架分析了php數(shù)組與json格式數(shù)據(jù)的轉(zhuǎn)換技巧,需要的朋友可以參考下2015-07-07