<?php
/*
* 中文字符截取
* @param string $string 被处理的字符串
* @param int $start 开始截取的位置
* @param int $length 截取的字符长度
* @param string $charset 字符编码
* @param string $dot 缩略符号
*
* @return string
*/function cutstr($string, $start, $length, $charset = "utf-8", $dot = ‘‘) {
if(function_exists("mb_substr")){
if(mb_strlen($string,$charset)>$length){
return mb_substr($string,$start,$length,$charset).$dot;
}
return mb_substr($string,$start,$length,$charset);
}
$new = ‘‘;
if($charset===‘gbk‘){
$string = iconv("gbk","utf-8",$string);
}
$str = preg_split(‘//u‘,trim($string));
for($i = $start,$len = 1;$i<count($str)-1 && $len<=$length;$i++,$len++){
$new .= $str[$i+1];
}
if($charset===‘gbk‘){
$new = iconv("utf-8","gbk",$new);
}
return count($str)-2<$length?$new:$new.$dot;
}
echo cutstr(‘暗色调adsa暗色调‘,0,1,‘utf-8‘,‘....‘);
?>