PHP Chinese character to pinyin

Source: Internet
Author: User
: This article describes how to convert Chinese characters into pinyin characters in PHP. For more information about PHP tutorials, see.

  -20319, 'Ai' =>-20317, 'any' =>-20304, 'ang '=>-20295, 'ao' =>-20292, 'ba' =>-20283, 'ba' =>-20265, 'ban' =>-20257, 'bang' =>-20242, 'bao' =>-20230, 'bei' =>-20051, 'Ben' =>-20036, 'beng' =>-20032, 'bi' =>-20026, 'bian '=>-20002, 'biao' =>-19990, 'bie '=>-19986, 'bin' =>-19982, 'Bing' =>-19976, 'Bo' =>-19805, 'bu '=>-19784, 'CA' =>-19775, 'Cai' =>-19774, 'can '=>-19763, 'cang' =>-19756, 'Cao '=>-19751, 'Ce' =>-19746, 'ceng' =>-19741, 'Cha '=>-19739, 'C Hai '=>-19728, 'Chan' =>-19725, 'Chang' =>-19715, 'chuno' =>-19540, 'ch' =>-19531, 'Chen '=>-19525, 'cheng' =>-19515, 'Chi' =>-19500, 'Chong '=>-19484, 'chou' =>-19479, 'chu' =>-19467, 'chuai' =>-19289, 'chuance' =>-19288, 'chuang '=>-19281, 'chui' =>-19275, 'chun' =>-19270, 'chuo' =>-19263, 'ci' =>-19261, 'cong' =>-19249, 'cou' =>-19243, 'cu '=>-19242, 'cuance' =>-19238, 'Cui' =>-19235, 'cun' =>-19227, 'cuo' =>-19224, 'da' =>-19218, 'Dai' =>-19212, 'Da N' =>-19038, 'Dang '=>-19023, 'Dao' =>-19018, 'D' =>-19006, 'deng' =>-19003, 'di' =>-18996, 'Dian' =>-18977, 'diao' =>-18961, 'di' =>-18952, 'Ding' =>-18783, 'diu' =>-18774, 'dong' =>-18773, 'dou' =>-18763, 'du' =>-18756, 'duany' =>-18741, 'dui' =>-18735, 'dun' =>-18731, 'Duo' =>-18722, 'E' =>-18710, 'en' =>-18697, 'ER' =>-18696, 'FA '=>-18526, 'fan' =>-18518, 'fang '=>-18501, 'fei' =>-18490, 'fen' =>-18478, 'feng' =>-18463, 'fo' =>-18448, 'fou' =>-1 8447, 'Fu' =>-18446, 'ga '=>-18239, 'gai' =>-18237, 'Gan' =>-18231, 'giang '=>-18220, 'gao' =>-18211, 'ge' =>-18201, 'gei' =>-18184, 'Gen' =>-18183, 'geng' =>-18181, 'gong' =>-18012, 'gou' =>-17997, 'GU' =>-17988, 'gua' =>-17970, 'guai' =>-17964, 'guany' =>-17961, 'Guang' =>-17950, 'Guan' =>-17947, 'gun' =>-17931, 'guo' =>-17928, 'ha' =>-17922, 'Hai' =>-17759, 'Han' =>-17752, 'hang' =>-17733, 'hao' =>-17730, 'hes' =>-17721, 'hei' =>-17703, 'hangzhou' =>-17701, 'Hangzhou' =>-17697, 'Hong '=>-17692, 'hou' =>-17683, 'hu' =>-17676, 'hua' =>-17496, 'huai' =>-17487, 'huany' =>-17482, 'huangt' =>-17468, 'hui' =>-17454, 'hun' =>-17433, 'huo' =>-17427, 'ji' =>-17417, 'ja' =>-17202, 'jian '=>-17185, 'Jiang '=>-16983, 'jiao' =>-16970, 'jie' =>-16942, 'Jin' =>-16915, 'Jing' =>-16733, 'jiong' =>-16708, 'jiu' =>-16706, 'ju' =>-16689, 'juany' =>-16664, 'jue '=>-16657, 'Jun' =>-16647, 'ka '=>-16474, 'Kai' =>-16470, 'kan' =>-1 6465, 'hang' =>-16459, 'kako' =>-16452, 'KE' =>-16448, 'Ken' =>-16433, 'keng' =>-16429, 'Kong' =>-16427, 'kou' =>-16423, 'Ku '=>-16419, 'kua' =>-16412, 'kuai' =>-16407, 'kuany' =>-16403, 'kuang' =>-16401, 'kuai' =>-16393, 'Kun' =>-16220, 'kuo' =>-16216, 'la' =>-16212, 'ler' =>-16205, 'lan' =>-16202, 'Lang '=>-16187, 'Lao' =>-16180, 'le' =>-16171, 'lei' =>-16169, 'leng' =>-16158, 'Lil' =>-16155, 'lia '=>-15959, 'liany' =>-15958, 'lilang' =>-15944, 'liao' =>- 15933, 'Lil' =>-15920, 'lin' =>-15915, 'Ling' =>-15903, 'liu' =>-15889, 'Long' =>-15878, 'loud' =>-15707, 'Lu' =>-15701, 'LV' =>-15681, 'luan' =>-15667, 'lue' =>-15661, 'lun '=>-15659, 'luo' =>-15652, 'Ma' =>-15640, 'Mai' =>-15631, 'man' =>-15625, 'MANG' =>-15454, 'Mao '=>-15448, 'me' =>-15436, 'MEI' =>-15435, 'Men '=>-15419, 'meng' =>-15416, 'MI' =>-15408, 'Mian' =>-15394, 'Miao' =>-15385, 'Min' =>-15377, 'min' =>-15375, 'Ming' =>-15369, 'miu' =>-1536 3, 'Mo' =>-15362, 'Mou' =>-15183, 'Mu '=>-15180, 'na' =>-15165, 'Nai' =>-15158, 'Nan '=>-15153, 'nang' =>-15150, 'nao' =>-15149, 'ne '=>-15144, 'nei' =>-15143, 'nen' =>-15141, 'neng' =>-15140, 'ni' =>-15139, 'nian' =>-15128, 'niang '=>-15121, 'niao' =>-15119, 'ni' =>-15117, 'nin' =>-15110, 'nin' =>-15109, 'Niu' =>-14941, 'nong' =>-14937, 'Nu '=>-14933, 'nv' =>-14930, 'nuan' =>-14929, 'Nue '=>-14928, 'nuo' =>-14926, 'O' =>-14922, 'ou' =>-14921, 'pa' =>-14914, 'Pai '=>-14908, 'pan' =>-14902, 'pang' =>-14894, 'pao' =>-14889, 'pei '=>-14882, 'pen' =>-14873, 'Peng' =>-14871, 'pi '=>-14857, 'pian' =>-14678, 'piao' =>-14674, 'pie' =>-14670, 'pin' =>-14668, 'ping' =>-14663, 'Po' =>-14654, 'put' =>-14645, 'qy' =>-14630, 'qia '=>-14594, 'Qian' =>-14429, 'Qiang '=>-14407, 'qiao' =>-14399, 'qie' =>-14384, 'Qin' =>-14379, 'Qing' =>-14368, 'qiong' =>-14355, 'Qiu '=>-14353, 'qu' =>-14345, 'quany' =>-14170, 'Que '=>-14159, 'qun' =>-14151, 'run' =>-14149, 'rang' =>-14145, 'rao' =>-14140, 're' =>-14137, 'ren' =>-14135, 'reng' =>-14125, 'Ri' =>-14123, 'Rong '=>-14122, 'rou' =>-14112, 'Ru '=>-14109, 'rule' =>-14099, 'Rui' =>-14097, 'run' =>-14094, 'ruo' =>-14092, 'sa '=>-14090, 'Sai' =>-14087, 'san' =>-14083, 'Shanghai' =>-13917, 'sao' =>-13914, 'se' =>-13910, 'sen' =>-13907, 'seng' =>-13906, 'Sha' =>-13905, 'shai' =>-13896, 'shance' =>-13894, 'Shang '=>-13878, 'shao '=>-13870, 'she' =>-13859, 'shen' =>-13847, 'sheng' =>-13831, 'shi' =>-13658, 'Shou' =>-13611, 'shu' =>-13601, 'shua '=>-13406, 'shuai' =>-13404, 'shuany' =>-13400, 'Shanghai' =>-13398, 'Shanghai' =>-13395, 'Shanghai' =>-13391, 'Shanghai' =>-13387, 'Si' =>-13383, 'png' =>-13367, 'sou' =>-13359, 'su' =>-13356, 'suan' =>-13343, 'sui' =>-13340, 'sun' =>-13329, 'suo' =>-13326, 'ta' =>-13318, 'Tai' =>-13147, 'tan' =>-13138, 'Shanghai' =>-13120, 'Tao' =>-13107, 'Te' =>-130 96, 'teng' =>-13095, 'ti' =>-13091, 'tiance' =>-13076, 'tiao' =>-13068, 'tie '=>-13063, 'ting' =>-13060, 'tong' =>-12888, 'tou' =>-12875, 'tu' =>-12871, 'tuany' =>-12860, 'Tui '=>-12858, 'tun' =>-12852, 'tuo' =>-12849, 'wa '=>-12838, 'wai' =>-12831, 'wan '=>-12829, 'Wang' =>-12812, 'Wei' =>-12802, 'wen' =>-12607, 'engg' =>-12597, 'wo' =>-12594, 'wu' =>-12585, 'Si' =>-12556, 'Xia '=>-12359, 'xian '=>-12346, 'Xiang' =>-12320, 'Xiao' =>-12300, 'xie' =>-121 20, 'sin' =>-12099, 'x' =>-12089, 'xiong' =>-12074, 'Xiu' =>-12067, 'Xu '=>-12058, 'xua' =>-12039, 'xue' =>-11867, 'xun '=>-11861, 'Ya' =>-11847, 'any' =>-11831, 'Yang' =>-11798, 'yunao' =>-11781, 'day' =>-11604, 'yi' =>-11589, 'In' =>-11536, 'in' =>-11358, 'yo' =>-11340, 'Yong '=>-11339, 'you' =>-11324, 'yu' =>-11303, 'yuanyuan '=>-11097, 'yue' =>-11077, 'yun' =>-11067, 'Za '=>-11055, 'zai' =>-11052, 'zany' =>-11045, 'zang' =>-11041, 'zao' =>-11038 ,' Ze '=>-11024, 'Zei' =>-11020, 'zn' =>-11019, 'zeng' =>-11018, 'zha' =>-11014, 'Zhai' =>-10838, 'zhan' =>-10832, 'zhang' =>-10815, 'zhao' =>-10800, 'zhes' =>-10790, 'Zhen' =>-10780, 'zheng' =>-10764, 'zhi' =>-10587, 'zhong' =>-10544, 'zhou' =>-10533, 'zhu' =>-10519, 'zhua' =>-10331, 'zhuai' =>-10329, 'zhua' =>-10328, 'zhuang' =>-10322, 'zhui' =>-10315, 'zhun' =>-10309, 'zhuo' =>-10307, 'zi' =>-10296, 'zong '=>-10281, 'zou' =>-10274, 'Zu' =>-10270, 'z Uan '=>-10262, 'zui' =>-10260, 'Zun '=>-10256, 'zuo' =>-10254 ); /*** encode Chinese characters into pinyin * @ param string $ str the string to be converted to pinyin * @ param string $ RetFormat return format [first: the first letter of each word | all: all pinyin | one: string Letter] * @ return string */public function get_pinyin ($ str, $ RetFormat = 'first') {$ GBK = iconv ('utf-8 ', 'gbk', $ str); $ UTF8 = iconv ('gbk', 'utf-8', $ GBK); if ($ UTF8! = $ Str) $ GBK = $ str; $ Buf = array (); for ($ I = 0, $ iLoop = strlen ($ GBK); $ I <$ iLoop; $ I ++) {$ Chr = ord ($ GBK {$ I}); if ($ Chr> 160) {$ Chr = ($ Chr <8) + ord ($ GBK {+ $ I})-65536;} if ('first' = $ RetFormat | 'one' = $ RetFormat) {$ Buf [] = substr ($ this-> zh2py ($ Chr), 0, 1 );} else {$ Buf [] = $ this-> zh2py ($ Chr) ;}} if ('first' ===$ RetFormat) {return implode ('', $ Buf);} elseif ('one' ==$ RetFormat) {return $ Buf [0];} else {return implode ('', $ Buf );}} /*** convert Chinese to pinyin (one character is processed each time) * @ param number $ iWORD the double byte of the character to be processed * @ return string pinyin */private function zh2py ($ iWORD) {if ($ iWORD> 0 & $ iWORD <160) {return chr ($ iWORD);} elseif ($ iWORD <-20319 | $ iWORD>-10247) {return '';} else {foreach ($ this-> data as $ py => $ code) {if ($ code> $ iWORD) break; $ result = $ py;} return $ result ;}}$ Pinyin = new Pinyin (); // The result is echo $ Pinyin-> get_pinyin ('test text '),'
'; // The result is echo $ Pinyin-> get_pinyin ('test text', 'all '),'
'; // The result is the first Pinyin echo $ Pinyin-> get_pinyin ('test text', 'one '),'
';

The above introduces the conversion of PHP Chinese characters to pinyin, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.