首页 » PHP » 随笔 » 阅读文章

smarty插件之支持中文字符截取

2010-09-01 19:47 10643 4 发表评论
标签:

smarty插件:名称是modifier.tcutf8.php ,这个插件是用于UTF8编码,由于原来的modifier_truncate.php不支持中文,所以写了一个插件。页面引用方法为:{$title|tcutf8:25}

<?php
function smarty_modifier_tcutf8($string, $length = 80,$cat=”)
{
   $null=””;
   $ar=array();
   preg_match_all(“/./u”,$string,$ar);
   $cont=join($null,array_slice($ar[0],0,$length));
   if(strlen($string)>$length){
    $cont.=$cat;
   }
   return $cont;
}

?>

本文地址:http://www.jwzzsw.com/archives/261.html

文章作者:思悟
版权所有 © 转载时请以链接形式注明作者和原始出处!

评论 共4条 (RSS 2.0) 发表评论

  1. 餐具包装机说道:

    博主写的文章真不错,支持,支持。。。

  2. 纺织机械说道:

    好好学习一下

  3. 餐具包装机说道:

    写得真有意思

  4. 护栏网说道:

    有意思,支持一下

发表评论

联系我 Contact Me

回到页首