129) { $arrPrevInitialPinyin[0] = $arrFirstPinyin[0]; } else { $arrPrevInitialPinyin[0] = substr($arrFirstPinyin[0], 0, 1); } foreach ($arrPinyinList as $arrPinyin) { $arrInitialPinyin = array(); foreach ($arrPrevInitialPinyin as $strPrevPinyin) { foreach ($arrPinyin as $strPinyin) { if (ord($strPinyin) > 129) { $arrInitialPinyin[] = $strPrevPinyin . $strPinyin; } else { $arrInitialPinyin[] = $strPrevPinyin . substr($strPinyin, 0, 1); } } } $arrPrevInitialPinyin = $arrInitialPinyin; } } if ($isAll === true) { $result['full'] = $arrFullPinyin; $result['initial'] = $arrInitialPinyin; } elseif ($isPolyphone === true) { if (($isInitial === true)) { $result = $arrInitialPinyin; } else { $result = $arrFullPinyin; } } else { if (($isInitial === true)) { $result = reset($arrInitialPinyin); } else { $result = reset($arrFullPinyin); } } return $result; } /* *获取字符串首个字符/首个汉字拼音大写 */ public function get_first_char($string){ $first = ''; $pinyin = self::ChineseToPinyin($string); if(!empty($pinyin)){ $first = strtoupper(substr($pinyin, 0, 1)); } if (!empty($first) && (ord($first) < 65 || ord($first) > 90)) { return ''; } return $first; } }