解析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…

相关文章

PHP yield关键字功能与用法分析

本文实例讲述了PHP yield关键字功能与用法。分享给大家供大家参考,具体如下: yield 关键字是php5.5版本推出的一个特性。生成器函数的核心是yield关键字。它最简单的调用...

PHP使用XMLWriter读写xml文件操作详解

本文实例讲述了PHP使用XMLWriter读写xml文件操作。分享给大家供大家参考,具体如下: 米扑科技旗下的多个产品,需要脚本自动生成sitemap.xml,于是重新温习一遍PHP X...

Linux环境下php实现给网站截图的方法

本文实例讲述了Linux环境下php实现给网站截图的方法。分享给大家供大家参考,具体如下: 第一步:下载wkhtmltopdf 复制代码 代码如下:[root@iZ94aawoublZ...

PHP实现生成带背景的图形验证码功能

本文实例讲述了PHP实现生成带背景的图形验证码功能。分享给大家供大家参考,具体如下: 以前我们利用php生成的都是无背景或同一色彩背景的验证码了,但这种验证容易给机器识别了,这里就来介绍...

PHP中数组转换为SimpleXML教程

SimpleXML扩展函数提供了将XML转换为对象的工具集。这些对象处理普通的属性选择器和数组迭代器。 示例1: <?php // 将php数组转换为xml文档的代码...