1. MySQL is sorted by the first letter of the pinyin Field Value
Keywords binary: selectName from topic order bybinary name ASC
2. Obtain the first letter of Chinese pinyin in PHP.
Directly call the following function. For example, Echo getinitial ("Dan ");
Function getinitial ($ Str)
{
$ ASC = ord (substr ($ STR, 0, 1 ));
If ($ ASC <160) // non-Chinese
{
If ($ ASC >=48 & $ ASC <= 57 ){
Return '1 ';// Number
} Elseif ($ ASC >=65 & $ ASC <= 90 ){
Return CHR ($ ASC ); // A--Z
} Elseif ($ ASC >=97 & $ ASC <= 122 ){
Return CHR ($ asc-32); // A -- Z
} Else {
Return '~ '; // Others
}
}
Else // Chinese
{
$ ASC = $ ASC * 1000 + ord (substr ($ STR, 1, 1 ));
// Get the first letter A--Z of Pinyin
If ($ ASC> = 176161 & $ ASC <176197 ){
Return 'a ';
} Elseif ($ ASC >=176197 & $ ASC <178193 ){
Return 'B ';
} Elseif ($ ASC >=178193 & $ ASC <180238 ){
Return 'C ';
} Elseif ($ ASC >=180238 & $ ASC <182234 ){
Return 'D ';
} Elseif ($ ASC >=182234 & $ ASC <183162 ){
Return 'E ';
} Elseif ($ ASC >=183162 & $ ASC <184193 ){
Return 'F ';
} Elseif ($ ASC >=184193 & $ ASC <185254 ){
Return 'G ';