解析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使用strrev翻转中文乱码问题的解决方法

本文实例讲述了PHP使用strrev翻转中文乱码问题的解决方法。分享给大家供大家参考,具体如下: 在用PHP中的strrve翻转中文时,会出现乱码情况 例如: header("Con...

将一维或多维的数组连接成一个字符串的php代码

复制代码 代码如下: /* * ————————————————- * @file : 5.php * @function : arr2str * @copyright : 2002-2...

PHP基于文件锁解决多进程同时读写一个文件问题示例

本文实例讲述了PHP基于文件锁解决多进程同时读写一个文件问题。分享给大家供大家参考,具体如下: 首先PHP是支持进程的而不支持多线程(这个先搞清楚了),如果是对于文件操作,其实你只需要给...

PHP中strpos、strstr和stripos、stristr函数分析

本文为大家分析了 PHP中strpos、strstr和stripos、stristr函数,供大家参考,具体内容如下 strpos mixed strpos ( string $hayst...

在php中判断一个请求是ajax请求还是普通请求的方法

/path/to/pkphp.com/script.php?ajax 在php脚本中使用如下方法判断: 复制代码 代码如下: if(isset($_GET['ajax'])) { ......