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

yipeiwu_com6年前PHP代码库
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…

相关文章

在WordPress中使用wp_count_posts函数来统计文章数量

做一个全站统计是不是很酷?长久的博客越来越少,何不给自己的一个统计,看看自己在这个博客上努力了多少,不但给自己也给游客,wp_count_posts是在 WordPress 中用来统计文...

PHP 程序员也要学会使用“异常”

网站完全开放的特性,决定了网站比任何传统软件都更希望做到“系统看起来永远都是能够正常工作的”,所以采用正确的程序错误处理方式尤为重要。理论上来说,如果设计足够完美,开发人员足够谨慎,程序...

PHP实现使用DOM将XML数据存入数组的方法示例

本文实例讲述了PHP实现使用DOM将XML数据存入数组的方法。分享给大家供大家参考,具体如下: <?php $doc = new DOMDocument('1.0','...

Notice: Undefined index: page in E:\PHP\test.php on line 14

治標不治本的就是將php.ini內的reporting部份修改,讓notice不顯示 error_reporting = E_ALL; display all errors, warni...

[PHP]实用函数2

1、产生随机字符串函数 复制代码 代码如下:function random($length) {  $hash = @#@#; ...