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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-18 我要评论
想了解解析smarty 截取字符串函数 truncate的用法介绍的相关内容吗,在本文为您仔细讲解smarty 截取字符串函数 truncate的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:smarty,截取字符串函数,truncate,下面大家一起来学习吧。
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…

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们