标签:function public return 字符串 start
方法一:
/**
* 截取utf8字符串
* @param string $str 字符串
* @param int $from 起始位
* @param int $len 结束们
* @return string
*/
public static function utf8Substr($str, $from, $len) {
return preg_replace(‘#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,‘ . $from . ‘}‘ .
‘((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,‘ . $len . ‘}).*#s‘, ‘$1‘, $str);
}
方法二:
function msubstr($str, $start, $len) {
$tmpstr = "";
$strlen = $start + $len;
for($i = 0; $i < $strlen; $i++) {
if(ord(substr($str, $i, 1)) > 0xa0) {
$tmpstr .= substr($str, $i, 2);
$i++;
} else
$tmpstr .= substr($str, $i, 1);
}
return $tmpstr;
}
标签:function public return 字符串 start
原文地址:http://jyb2014.blog.51cto.com/9155315/1569216