<?php
/*統計中文字符長度*/
function abslength($str){
if(empty($str)){
return 0;
}
if(function_exists('mb_strlen')){
return mb_strlen($str,'utf-8');
}
else {
preg_match_all("/./u", $str, $ar);
return count($ar[0]);
}
}
/*截取中文字符*/
function utf8_substr($str,$start=0) {
if(empty($str)){
return false;
}
if (function_exists('mb_substr')){
if(func_num_args() >= 3) {
$end = func_get_arg(2);
return mb_substr($str,$start,$end,'utf-8');
}
else {
mb_internal_encoding("UTF-8");
return mb_substr($str,$start);
}
}
else {
$null = "";
preg_match_all("/./u", $str, $ar);
if(func_num_args() >= 3) {
$end = func_get_arg(2);
return join($null, array_slice($ar[0],$start,$end));
}
else {
return join($null, array_slice($ar[0],$start));
}
}
}
?>
*