php计算字符串长度

/**
* 计算字符串的长度(非字节)
* 先用正则将字符串分解为个体单元,然后再计算单元的个数即得出字符串的长度
* from wordpress
* @param string $string
* @return int
*/
public static function getUtf8CharLength($string = null)
{
// 将字符串分解为单元
preg_match_all("/./us", $string, $match);
// 返回单元个数
return count($match[0]);
}