//获取字符串中英文混合长度 function get_strlen($str, $charset = 'utf-8') { if ($charset == 'utf-8') $str = iconv('utf-8', 'gb2312', $str); $num = strlen($str); $cnNum = 0; for ($i = 0; $i < $num; $i++) { if (ord(substr($str, $i + 1, 1)) > 127) { $cnNum++; $i++; } } $enNum = $num - ($cnNum * 2); return $cnNum * 2 + $enNum; }
Done !