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

2015-01-24信息快讯网

本篇文章是对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…
PHP下获取上个月、下个月、本月的日期(strtotime,date)
分享下页面关键字抓取components.arrow.com站点代码
php缓冲 output_buffering和ob_start使用介绍
php中自定义函数dump查看数组信息类似var_dump
PHP类继承 extends使用介绍
php中filter函数验证、过滤用户输入的数据
codeigniter框架批量插入数据
百度站点地图(百度sitemap)生成方法分享
php二维数组排序方法(array_multisort usort)
ubuntu12.04使用c编写php扩展模块教程分享
php使用strtotime和date函数判断日期是否有效代码分享
php制作unicode解码工具(unicode编码转换器)代码分享
php安装xdebug/php安装pear/phpunit详解步骤(图)
sae使用smarty模板的方法
PHP中func_get_args(),func_get_arg(),func_num_args()的区别
PHP取整函数:ceil,floor,round,intval的区别详细解析
解析如何在PHP下载文件名中解决乱码的问题
完美解决令人抓狂的zend studio 7代码提示(content Assist)速度慢的问题
探讨Smarty中如何获取数组的长度以及smarty调用php函数的详解
php echo, print, print_r, sprintf, var_dump, var_expor的使用区别
Android ProgressBar进度条和ProgressDialog进度框的展示DEMO
解析二进制流接口应用实例 pack、unpack、ord 函数使用方法
使用array mutisort 实现按某字段对数据排序
解析CodeIgniter自定义配置文件
深入array multisort排序原理的详解
使用Smarty 获取当前日期时间和格式化日期时间的方法详解
解析smarty模板中类似for的功能实现
php class中public,private,protected的区别以及实例分析
解析:通过php socket并借助telnet实现简单的聊天程序
ubuntu下编译安装xcache for php5.3 的具体操作步骤
CodeIgniter图像处理类的深入解析
php unset全局变量运用问题的深入解析
解析php中call_user_func_array的作用
PHP 常用数组内部函数(Array Functions)介绍
©2014-2024 dbsqp.com