Current location - Quotes Website - Signature design - How to get the first letter of Chinese pinyin in php
How to get the first letter of Chinese pinyin in php
//Convert Chinese characters into Pinyin (uncommon words are not supported)

$ Pinyin? =? $ this-& gt; Utf8_to ("I'm from China");

//Convert Chinese characters into Pinyin (uncommon words are not supported)

Function () {

Echo? $ this-& gt; Utf8_to ("I am a good man");

}

/**

*? The following is Chinese to Pinyin.

*? @param? $s

*? @param? Bull? $isfirst

*? @ Return? line

*/

Public? Static electricity Function? utf8_to($s,$isfirst? =? False)? {

Return? self::to(self::utf8 _ to _ GB 23 12($ s),? $ is first);

}

Public? Static electricity Function? utf8_to_gb23 12($s)? {

Return? iconv('UTF-8 ',? GB 23 12// ignore',? $ s);

}

//? The string must be encoded as GB23 12.

Public? Static electricity Function? To ($ TERM, $isfirst? =? False)? {

$res? =? '';

$len? =? Strlen (USD);

$ pinyin _arr? =? Self::get _ Pinyin _ array ();

for($ I = 0; ? $ i & lt$ len? $i++)? {

$ascii? =? order($ s { $ I });

if($ascii? & gt? 0x80)? {

$ascii2? =? order($ s { ++ $ I });

$ascii? =? $ascii? *? 256? +? $ascii2? -? 65536;

}

if($ascii? & lt? 255? & amp& amp? $ascii? & gt? 0)? {

If (($ascii? & gt=? 48? & amp& amp? $ascii? & lt=? 57)? ||? ($ascii? & gt=? 97? & amp& amp? $ascii? & lt=? 122))? {

$res? . =? $ s { $ I }; ? //? 0-9? All-encompassing

}elseif($ascii? & gt=? 65? & amp& amp? $ascii? & lt=? 90)? {

$res? . =? strtolower($ s { $ I }); ? //? A-Z

} Otherwise {

$res? . =? '_';

}

}elseif($ascii? & lt? -203 19? ||? $ascii? & gt? - 10247)? {

$res? . =? '_';

} Otherwise {

Foreach($ pinyin _arr? As? $ py = & gt$asc)? {

If ($asc? & lt=? $ascii)? {

$res? . =? $isfirst$py{0}? :? $ py

Break;

}

}

}

}

Return? $ res

}

Public? Static electricity Function? to_first($s)? {

$ascii? =? Order ($ s {0});

if($ascii? & gt? 0xE0)? {

$s? =? self::utf8 _ to _ GB 23 12 $ s { 0 }。 $s{ 1}。 $ s { 2 });

}elseif($ascii? & lt? 0x80)? {

if($ascii? & gt=? 65? & amp& amp? $ascii? & lt=? 90)? {

Return? strtolow($ s { 0 });

}elseif($ascii? & gt=? 97? & amp& amp? $ascii? & lt=? 122)? {

Return? $ s { 0 };

} Otherwise {

Return? Fake;

}

}

if(strlen $ s)? & lt? 2)? {

Return? Fake;

}

$asc? =? Order ($s{0})? *? 256? +? Order ($s{ 1})? -? 65536;

if($ ASC & gt; =-203 19? & amp& amp? $ asc & lt=-20284)? Return? a’;

if($ ASC & gt; =-20283? & amp& amp? $ asc & lt=- 19776)? Return? b’;

if($ ASC & gt; =- 19775? & amp& amp? $ asc & lt=- 192 19)? Return? c’;

if($ ASC & gt; =- 192 18? & amp& amp? $ asc & lt=- 187 1 1)? Return? d’;

if($ ASC & gt; =- 187 10? & amp& amp? $ asc & lt=- 18527)? Return? e’;

if($ ASC & gt; =- 18526? & amp& amp? $ asc & lt=- 18240)? Return? f’;

if($ ASC & gt; =- 18239? & amp& amp? $ asc & lt=- 17923)? Return? g’;

if($ ASC & gt; =- 17922? & amp& amp? $ asc & lt=- 174 18)? Return? h’;

if($ ASC & gt; =- 174 17? & amp& amp? $ asc & lt=- 16475)? Return? j’;

if($ ASC & gt; =- 16474? & amp& amp? $ asc & lt=- 162 13)? Return? k’;

if($ ASC & gt; =- 162 12? & amp& amp? $ asc & lt=- 1564 1)? Return? l’;

if($ ASC & gt; =- 15640? & amp& amp? $ asc & lt=- 15 166)? Return? m’;

if($ ASC & gt; =- 15 165? & amp& amp? $ asc & lt=- 14923)? Return? n’;

if($ ASC & gt; =- 14922? & amp& amp? $ asc & lt=- 149 15)? Return? o’;

if($ ASC & gt; =- 149 14? & amp& amp? $ asc & lt=- 1463 1)? Return? p’;

if($ ASC & gt; =- 14630? & amp& amp? $ asc & lt=- 14 150)? Return? q’;

if($ ASC & gt; =- 14 149? & amp& amp? $ asc & lt=- 1409 1)? Return? r’;

if($ ASC & gt; =- 14090? & amp& amp? $ asc & lt=- 133 19)? Return? s’;

if($ ASC & gt; =- 133 18? & amp& amp? $ asc & lt=- 12839)? Return? t’;

if($ ASC & gt; =- 12838? & amp& amp? $ asc & lt=- 12557)? Return? w’;

if($ ASC & gt; =- 12556? & amp& amp? $ asc & lt=- 1 1848)? Return? x’;

if($ ASC & gt; =- 1 1847? & amp& amp? $ asc & lt=- 1 1056)? Return? y’;

if($ ASC & gt; =- 1 1055? & amp& amp? $ asc & lt=- 10247)? Return? z’;

Return? Fake;

}

Public? Static electricity Function? Get _ Pinyin _ Array ()? {

Static electricity $ py _ arr

if(isset($py_arr))? Return? $ py _ arr

$k? =? a | ai | an | ang | ao | ba | Bai | ban | bang | Bao | Bei | Ben | beng | bi | bian | Biao | bie | bin | bing | bo | bu | ca | Cai | Cang | Cao | ce | Zeng | Cha | Chai | Chan | Chang | Chao | Che | Chen | Chen | Chi | Chong | Chou | Chu | Chuan | Chu | Ci | Cong | Cou | Cu | Juan | Cui | Cui | CuO | da | Dai | Dan | dang | Dao | de | Deng | de | Deng

$v? =? '-203 19|-203 17|-20304|-20295|-20292|-20283|-20265|-20257|-20242|-20230|-2005 1|-20036|-20032|-20026|-20002|- 19990|- / kloc-0/9986| - 19982|- 19976|- 19805|- 19784|- 19775|- 19774|- 19763|- 19756|- 1975 / kloc-0/|- 19746| - 1974 1|- 19739|- 19728|- 19725|- 197 15|- 19540|- 1953 / kloc-0/|- 19525|- 195 15| - 19500|- 19484|- 19479|- 19467|- 19289|- 19288|- 1 928 1|- 19275|- 19270|- 19263| - 1926 1|- 19249|- 19243|- 19242|- 19238|- / kloc-0/9235|- 19227|- 19224|- 192 18|- 192 12| - 19038|- 19023|- 190 18|- / kloc-0/9006|- 19003|- 18996|- 18977|- 1896 1|- 18952|- 18783| - 18774|- 18773|- / kloc-0/8763|- 18756|- 1874 1|- 18735|- 1873 1|- 18722|- 187 10|- 18697| - / kloc-0/8696|- 18526|- 185 18|- 1850 1|- 18490|- 18478|- 18463|- 18448|- 18447| - 18446| - 18239|- 18237|- 1823 1|- 18220|- 182 1 1|- 1820 1|- 1 8 184|- 18 183| - 18 18 1|- 180 12|- 17997|- 17988|- 17970|- 1 7964|- 1796 1|- 17950|- 17947| - 1793 1|- 17928|- 17922|- 17759|- 17752|- / kloc-0/7733|- 17730|- 1772 1|- 17703|- 1770 1| - 17697|- 17692|- 17683|- 17676| - 17496|- 17487|- 17482|- 17468|- 17454|- 17433|- 17427| - 174 17|- 17202|- / kloc-0/7 185|- 16983|- 16970|- 16942|- 169 15|- 16733|- 16708|- 16706| - 16689| - 16664|- 16657|- 16647|- 16474|- 16470|- 16465|- 16459|- 16452|- 16448|- 16433| - 16429|- 16427|- 16423|- 164 19|- 164 12|- 16407|- 16403|- 1640 1|- / kloc-0/6393|- 16220| - 162 16|- 162 12|- 16205|- 16202|- 16 187|- 16 180| - 16 17 1|- 16 169| - 16 158|- 16 155|- 15959|- 15958|- 15944|- / kloc-0/5933|- 15920|- 159 15|- 15903|- 15889| - 15878|- 15707|- 1570 1|- 1568 / kloc-0/|- 15667|- 1566 1|- 15659|- 15652|- 15640| - 1563 1|- 15625|- 15454|- / kloc-0/5448|- 15436|- 15435|- 154 19|- 154 16|- 15408|- 15394| - 15385|- 15377| - 15375|- 15369|- 15363|- 15362|- 15 183|- 15 180|- 15 165| - 15 1 58|- 15 153|- 15 150|- 15 149|- 15 144|- 15 143|- 15 14 1| - 15 140|- 15 139|- 15 128|- 15 12 1|- 15 1 19|- 15 / kloc-0/ 17| - 15 1 10|- 15 109|- 1494 1|- 14937|- 14933|- 14930|- / kloc-0/4929|- 14928|- 14926| - 14922|- 1492 1|- 149 14|- 14908|- 14902|- 14894| - 14889|- 14882|- 14873|- 1487 1| - 14857|- 14678|- 14674|- 14670|- 14668|- / kloc-0/4663|- 14654|- 14645|- 14630|- 14594|- 14429| - 14407|- 14399|- 14384|- 14379| - 14368|- 14355|- 14353|- 14345|- 14 170|- 14 159| - 14 15 1|- 1 4 149|- 14 145|- 14 140|- 14 137|- 14 135|- 14 125| - 14 1 23|- 14 122|- 14 1 12|- 14 109|- 14099|- 14097|- 14094|- 14092|- 1 4090| - 14087|- 14083|- 139 17|- 139 14|- 139 10|- 13907|- 13906|- 13905| - 13896|- 13894| - 13878|- 13870|- 13859|- 13847|- 1383 1|- 13658|- 136 1 1|- 1360 1|- 13406| - 13404|- 13400|- 13398|- 13395|- 1339 1|- 13387|- / kloc-0/3383|- 13367|- 13359|- 13356|- 13343| - 13340|- 13329|- 13326|- 133 18|- / kloc-0/3 147|- 13 138|- 13 120|- 13 107|- 13096| - 13095|- 1309 1|- / kloc-0/3076|- 13068|- 13063|- 13060|- 12888|- 12875|- 1287 1|- 12860| - 12858|- / kloc-0/2852|- 12849|- 12838|- 1283 1|- 12829|- 128 12|- 12802|- 12607|- 12597| - 12594|- 12585|- 12556|- 12359|- 12346|- 12320|- 12300|- 12 120|- 12099|- / kloc-0/2089|- 12074| - 12067|- 12058|- 12039|- 1 1867|- 1 186 1|- 1 1847| - 1 183 1|- 1 1798| - 1 178 1|- 1 1604|- 1 1589|- 1 / kloc-0/536|- 1 1358|- 1 1340|- 1 1339| - 1 1324|- 1 1303|- 1 1097| - 1 1077|- 1 1067|- 1 1055|- 1 1052| - 1 1045|- 1 104 1|- / kloc-0/ 1038|- 1 1024|- 1 1020|- 1 10 19| - 1 10 18|- 1 1 0 14|- 10838|- 10832|- 108 15|- 10800|- 10790|- 10780|- 10764| - 10587|- / kloc-0/0544|- 10533|- 105 19|- 1033 1|- 10329|- 10328|- 10322|- 103 15|- / kloc-0/0309| - 10307|- 10296|- 1028 1|- 10274|- 10270|- 10262|- 10260|- 10256|- 10254';

$key? =? Decomposition ('|',? $ k);

Val? =? Decomposition ('|',? $ v);

$py_arr? =? array_combine($key,? $ val);

arsort($ py _ arr);

Return? $ py _ arr

}