ThinkPHP 3.2.2 视图模板中使用字符串截取函数
时间:2014-12-08 21:07:48
收藏:0
阅读:3164
在项目的 Common/function.php 文件里( 项目结构如图 ) 添加函数:
/*字符串截断函数+省略号*/ function subtext($text, $length) { if(mb_strlen($text, ‘utf8‘) > $length) return mb_substr($text, 0, $length, ‘utf8‘).‘...‘; return $text; }
然后在模板文件中这样写 ( 使用 TP 模板 ),例如在循环中:
<volist name="list" id="vo"> {$vo.comment|subtext=40} </volist>
前台页面显示 ( 会带... ):
附:
项目结构:
原文:http://www.cnblogs.com/dee0912/p/4151872.html
评论(0)