>  기사  >  백엔드 개발  >  解析smarty 截取字符串函数 truncate的用法介绍_PHP教程

解析smarty 截取字符串函数 truncate的用法介绍_PHP教程

WBOY
WBOY원래의
2016-07-21 15:04:45869검색

smarty truncate 截取字符串
从字符串开始处截取某长度的字符,默认的长度为80
指定第二个参数作为截取字符串的长度
默认情况下,smarty会截取到一个词的末尾,
如果需要精确到截取多少个字符可以使用第三个参数,将其设为”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}

输出结果:
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…

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/327740.htmlTechArticlesmarty truncate 截取字符串 从字符串开始处截取某长度的字符,默认的长度为80 指定第二个参数作为截取字符串的长度 默认情况下,smarty会截...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.