/** * 函数名称:isChinese * 简要描述:检查是否输入为汉字 * 输入:string * 输出:boolean **/ public static function isChinese($str) { $words = UtilHelper::chineseSplit($str); foreach ($words as $word) { if (ord($word) < 224 || ord($word) > 240) { return false; } } return true; }
/** * * Fetch the first letter of the chinese word * @param string $_String * @param string $_Code */ public function words2Short($_String, $_Code = 'gb2312', $_lenght = 2) { $firstLetter = array(); $len = 0; // $str="x个小姑娘去kfc吃chicken,飞刀已出手,nobody看到什么时候出手的,Mr'Li手中仍握着那个木雕,但刀已不在noanymore"; $_String = UtilHelper::chineseSplit($_String); // UtilHelper::writeToFile($_String); foreach ($_String as $letter) { $len++; if ($len < 3) { $letter = $this->words2PinYin($letter, 1); $firstLetter[] = substr($letter, 0, 1); } else { break; } } return implode('', $firstLetter); // Helper::dump($firstLetter); }