//php get Chinese characters Pinyin first letter Publicfunction Getfirstword ($str) {if(Empty ($STR)) {return "';} $fchar=ord ($str {0}); if($fchar >=ord ('A') && $fchar <=ord ('Z'))returnStrtoupper ($str {0}); $s 1=iconv ('UTF-8','gb2312', $STR); $s 2=iconv ('gb2312','UTF-8', $s 1); $s= $s 2== $str?$s 1: $str; $ASC=ord ($s {0})* the+ord ($s {1})-65536; if($asc >=-20319&& $ASC <=-20284)return 'A'; if($asc >=-20283&& $ASC <=-19776)return 'B'; if($asc >=-19775&& $ASC <=-19219)return 'C'; if($asc >=-19218&& $ASC <=-18711)return 'D'; if($asc >=-18710&& $ASC <=-18527)return 'E'; if($asc >=-18526&& $ASC <=-18240)return 'F'; if($asc >=-18239&& $ASC <=-17923)return 'G'; if($asc >=-17922&& $ASC <=-17418)return 'H'; if($asc >=-17417&& $ASC <=-16475)return 'J'; if($asc >=-16474&& $ASC <=-16213)return 'K'; if($asc >=-16212&& $ASC <=-15641)return 'L'; if($asc >=-15640&& $ASC <=-15166)return 'M'; if($asc >=-15165&& $ASC <=-14923)return 'N'; if($asc >=-14922&& $ASC <=-14915)return 'O'; if($asc >=-14914&& $ASC <=-14631)return 'P'; if($asc >=-14630&& $ASC <=-14150)return 'Q'; if($asc >=-14149&& $ASC <=-14091)return 'R'; if($asc >=-14090&& $ASC <=-13319)return 'S'; if($asc >=-13318&& $ASC <=-12839)return 'T'; if($asc >=-12838&& $ASC <=-12557)return 'W'; if($asc >=-12556&& $ASC <=-11848)return 'X'; if($asc >=-11847&& $ASC <=-11056)return 'Y'; if($asc >=-11055&& $ASC <=-10247)return 'Z'; $py=NewPyinitialscontroller (); $result= $pygetinitials ($STR); $result= Ucfirst ($result [0]); $array= ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O', 'P','Q','R','S','T','U','V','W','X','Y','Z']; if(!In_array ($result, $array)) { return '#'; } //return Ucfirst ($result [0]);}
PHP get Chinese characters Pinyin first letter star small stack