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

yipeiwu_com5年前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…

相关文章

用PHP伪造referer突破网盘禁止外连的代码

比如我放纳米盘里的文件http://img.namipan.com/downfile/da333ee178bdad6531d1ec1540cf86277c116b6300887600/0...

常见的PHP五种设计模式小结

常见的PHP五种设计模式小结

设计模式 一书将设计模式引入软件社区,该书的作者是 Erich Gamma、Richard Helm、Ralph Johnson 和 John Vlissides Design(俗称 “...

PHP函数strip_tags的一个bug浅析

PHP 函数 strip_tags 提供了从字符串中去除 HTML 和 PHP 标记的功能,该函数尝试返回给定的字符串 str 去除空字符、HTML 和 PHP 标记后的结果。 由于 s...

php使用file函数、fseek函数读取大文件效率对比分析

php读取大文件可以使用file函数和fseek函数,但是二者之间效率可能存在差异,本文章向大家介绍php file函数与fseek函数实现大文件读取效率对比分析,需要的朋友可以参考一下...

PHP使用OB缓存实现静态化功能示例

本文实例讲述了PHP使用OB缓存实现静态化功能。分享给大家供大家参考,具体如下: 实现步骤 1、创建测试数据表并且写入数据 2、实现后台的更新操作。使用OB缓存针对每一个内容生成对应的H...