解析smarty 截取字符串函數(shù) truncate的用法介紹
更新時(shí)間:2013年06月20日 12:01:32 作者:
本篇文章是對(duì)smarty 截取字符串函數(shù) truncate的用法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
smarty truncate 截取字符串
從字符串開始處截取某長(zhǎng)度的字符,默認(rèn)的長(zhǎng)度為80
指定第二個(gè)參數(shù)作為截取字符串的長(zhǎng)度
默認(rèn)情況下,smarty會(huì)截取到一個(gè)詞的末尾,
如果需要精確到截取多少個(gè)字符可以使用第三個(gè)參數(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…
從字符串開始處截取某長(zhǎng)度的字符,默認(rèn)的長(zhǎng)度為80
指定第二個(gè)參數(shù)作為截取字符串的長(zhǎng)度
默認(rèn)情況下,smarty會(huì)截取到一個(gè)詞的末尾,
如果需要精確到截取多少個(gè)字符可以使用第三個(gè)參數(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)文章
PHP執(zhí)行php.exe -v命令報(bào)錯(cuò)的解決方案
這篇文章主要介紹了PHP執(zhí)行php.exe -v命令報(bào)錯(cuò)的解決方案,文中通過圖文講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-12-12
PHP合并數(shù)組+與array_merge的區(qū)別分析
PHP中兩個(gè)數(shù)組合并可以使用+或者array_merge,但之間還是有區(qū)別的,而且這些區(qū)別如果了解不清楚項(xiàng)目中會(huì)要命的!2010-08-08
php獲取網(wǎng)頁(yè)里所有圖片并存入數(shù)組的方法
這篇文章主要介紹了php獲取網(wǎng)頁(yè)里所有圖片并存入數(shù)組的方法,涉及php正則匹配及數(shù)組操作的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04
php計(jì)算函數(shù)執(zhí)行時(shí)間的方法
這篇文章主要介紹了php計(jì)算函數(shù)執(zhí)行時(shí)間的方法,以md5函數(shù)加密運(yùn)行時(shí)間為例分析了php計(jì)算函數(shù)運(yùn)行時(shí)間的技巧,需要的朋友可以參考下2015-03-03
thinkphp5使用bootstrapvalidator進(jìn)行異步驗(yàn)證郵箱的示例
這篇文章主要介紹了thinkphp5使用bootstrapvalidator進(jìn)行異步驗(yàn)證郵箱的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-10-10

