首页 > 其他 > 详细

msubstr截取中文

时间:2015-03-04 12:41:53      阅读:297      评论:0      收藏:0      [点我收藏+]
 1 {$vons.title|msubstr=0,26} 像这样,总是显示错误,说msubstr函数未定义,
 2 在使用这个函数之前是否需要引入什么文件?
 3 Common/common.php中定义函数:
 4 
 5 function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true)
 6 {
 7     if(function_exists("mb_substr")){
 8             if ($suffix && strlen($str)>$length)
 9                 return mb_substr($str, $start, $length, $charset)."...";
10         else
11                  return mb_substr($str, $start, $length, $charset);
12     }
13     elseif(function_exists(‘iconv_substr‘)) {
14             if ($suffix && strlen($str)>$length)
15                 return iconv_substr($str,$start,$length,$charset)."...";
16         else
17                 return iconv_substr($str,$start,$length,$charset);
18     }
19     $re[‘utf-8‘]   = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
20     $re[‘gb2312‘] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
21     $re[‘gbk‘]    = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
22     $re[‘big5‘]   = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
23     preg_match_all($re[$charset], $str, $match);
24     $slice = join("",array_slice($match[0], $start, $length));
25     if($suffix) return $slice."…";
26     return $slice;
27 }
28 
29 就是这么简单

 

msubstr截取中文

原文:http://www.cnblogs.com/xiaolang1/p/4312812.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!