当用户提交数据为中英数字混排时计算长度
?
/**
?* UTF-8编码情况下 *
?* 计算字符串的长度 *
?* @param?? string????? $str??????? 字符串
?*
?* @return? array
?*/
function strLength($str)
{
??? if(empty($str)) return 0;
??? $length = strlen(preg_replace('/[\x00-\x7F]/', '', $str));
??? $arr['en'] = strlen($str) - $length;
??? $arr['cn'] = intval($length / 3);//编码GBK,除以2
???
???
???
??? return (int)($arr['cn'] + $arr['en']/2);
}