首页 > 代码库 > 检测中文长度gbk下2个字节

检测中文长度gbk下2个字节

//$str = ‘fff&sdf你是sdf好fdf啊b歌hello中world‘;
$str = ‘d你b_fff是好啊歌中潺潺 ‘;
echo chineselength($str)."-----<br>";
function chineselength($str){
    $s=iconv("utf-8","gbk",$str);
    //echo $s;die();
    //$int=preg_match_all("/[\x{4e00}-\x{9fa5}]+/u", $s, $result);
    $count=0;
    $int=preg_match_all("/[".chr(0xa1)."-".chr(0xff)."]+/", $s, $result);
    foreach($result[0] as $k=>$v){
        $count+=mb_strlen($v,"gbk");
    }
    return $count;
}

检测中文长度gbk下2个字节