The first letter of Chinese characters in php to pinyin. After running the program, some characters in the string cannot be converted. If you enter these words separately, you can directly convert them to read the first letter of the alphabet. It won't work in the string. The program code is as follows: & nbsp; & lt ;? Php & nbsp; function & nbsp; getfirstchar ($ s0) {& nbsp; & nbsp php Chinese character to pinyin first letter problem.
After running the program, some characters in the string cannot be converted. If you enter these words separately, you can directly convert them to read the first letter of the alphabet.
It won't work in the string. The program code is as follows:
Function getfirstchar ($ s0 ){
$ Fchar = ord ($ s0 {0 });
If ($ fchar> = ord ("a") and $ fchar <= ord ("Z") return strtoupper ($ s0 {0 });
$ S1 = iconv ("UTF-8", "gb2312", $ s0 );
$ S2 = iconv ("gb2312", "UTF-8", $ s1 );
If ($ s2 = $ s0) {$ s = $ s1;} else {$ s = $ s0 ;}
$ Asc = ord ($ s {0}) * 256 + ord ($ s {1})-65536;
If ($ asc >=- 20319 and $ asc <=-20284) return "";
If ($ asc >=- 20283 and $ asc <=-19776) return "B ";
If ($ asc >=- 19775 and $ asc <=-19219) return "C ";
If ($ asc >=- 19218 and $ asc <=-18711) return "D ";
If ($ asc >=- 18710 and $ asc <=-18527) return "E ";
If ($ asc >=- 18526 and $ asc <=-18240) return "F ";
If ($ asc >=- 18239 and $ asc <=-17923) return "G ";
If ($ asc >=- 17922 and $ asc <=-17418) return "H ";
If ($ asc >=- 17417 and $ asc <=-16475) return "J ";
If ($ asc >=- 16474 and $ asc <=-16213) return "K ";
If ($ asc >=- 16212 and $ asc <=-15641) return "L ";
If ($ asc >=- 15640 and $ asc <=-15166) return "M ";
If ($ asc >=- 15165 and $ asc <=-14923) return "N ";
If ($ asc >=- 14922 and $ asc <=-14915) return "O ";
If ($ asc >=- 14914 and $ asc <=- 14631) return "P ";
If ($ asc >=- 14630 and $ asc <=-14150) return "Q ";
If ($ asc >=- 14149 and $ asc <=-14091) return "R ";
If ($ asc >=- 14090 and $ asc <=-13319) return "S ";
If ($ asc >=- 13318 and $ asc <=-12839) return "T ";
If ($ asc >=- 12838 and $ asc <=-12557) return "W ";
If ($ asc >=- 12556 and $ asc <=-11848) return "X ";
If ($ asc >=- 11847 and $ asc <=-11056) return "Y ";
If ($ asc >=- 11055 and $ asc <=- 10247) return "Z ";
Return null;
}
Function pinyin1 ($ zh ){
$ Ret = "";
$ S1 = iconv ("UTF-8", "gb2312", $ zh );
$ S2 = iconv ("gb2312", "UTF-8", $ s1 );
If ($ s2 = $ zh) {$ zh = $ s1 ;}
For ($ I = 0; $ I <strlen ($ zh); $ I ++ ){
$ S1 = substr ($ zh, $ I, 1 );
$ P = ord ($ s1 );
If ($ p & gt; 160 ){
$ S2 = substr ($ zh, $ I ++, 2 );
$ Ret. = getfirstchar ($ s2 );
} Else {
$ Ret. = $ s1;
}
}
Return $ ret;