/** * 計算字符串的長度(非字節) * 先用正則將字符串分解爲個體單元,而後再計算單元的個數即得出字符串的長度 * from wordpress * @param string $string * @return int */public static function getUtf8CharLength($string = null){ // 將字符串分解爲單元 preg_match_all("/./us", $string, $match); // 返回單元個數 return count($match[0]);}