A function that converts Chinese characters into pinyin.

Source: Internet
Author: User
Many problems are caused by Chinese characters. if the file name is better to use Chinese characters, the current solution is to generate an ID, this ID is used as a file name. if the url contains Chinese characters, the current solution often uses urlencode encoding and now uses this conversion, which is much better. principle: using multi-dimensional array 1. add index 2. traverse the array? $ Darray (arra

Many problems are caused by Chinese characters.
For example, it is best not to use Chinese characters for file names.
The solution is to generate an ID, which is used as the file name.
If the url contains Chinese characters on the webpage, errors often occur.
The current solution generally uses urlencode encoding.

It's much better to use this conversion.

Principle: multidimensional array
1. add an index
2. traverse the array

$ D = array (
Array (& quot; a & quot;,-20319 ),
Array ("ai",-20317 ),
Array ("an",-20304 ),
Array (& quot; ang & quot;,-20295 ),
Array ("ao",-20292 ),
Array (& quot; ba & quot;,-20283 ),
Array ("bai",-20265 ),
Array ("ban",-20257 ),
Array (& quot; bang & quot;,-20242 ),
Array ("bao",-20230 ),
Array (& quot; bei & quot;,-20051 ),
Array ("ben",-20036 ),
Array (& quot; beng & quot;,-20032 ),
Array ("bi",-1, 20026 ),
Array ("bian",-20002 ),
Array ("biao",-19990 ),
Array ("bie",-19986 ),
Array ("bin",-19982 ),
Array ("bing",-19976 ),
Array ("bo",-19805 ),
Array ("bu",-19784 ),
Array ("ca",-19775 ),
Array ("cai",-19774 ),
Array ("can",-19763 ),
Array ("cang",-19756 ),
Array ("cao",-19751 ),
Array (& quot; ce & quot;,-19746 ),
Array (& quot; ceng & quot;,-19741 ),
Array (& quot; cha & quot;,-19739 ),
Array ("chai",-19728 ),
Array ("chan",-19725 ),
Array ("chang",-19715 ),
Array ("chao",-19540 ),
Array (& quot; che & quot;,-19531 ),
Array ("chen",-19525 ),
Array ("cheng",-19515 ),
Array ("chi",-19500 ),
Array (& quot; chong & quot;,-19484 ),
Array ("chou",-19479 ),
Array ("chu",-19467 ),
Array ("chuai",-19289 ),
Array ("chuan",-19288 ),
Array ("chuang",-19281 ),
Array ("chui",-19275 ),
Array (& quot; chun & quot;,-19270 ),
Array ("chuo",-19263 ),
Array ("ci",-1, 19261 ),
Array (& quot; cong & quot;,-19249 ),
Array ("cou",-19243 ),
Array ("cu",-19242 ),
Array ("cuan",-19238 ),
Array ("cui",-19235 ),
Array (& quot; cun & quot;,-19227 ),
Array ("cuo",-19224 ),
Array ("da",-19218 ),
Array ("dai",-19212 ),
Array ("dan",-19038 ),
Array ("dang",-19023 ),
Array ("dao",-19018 ),
Array (& quot; de & quot;,-19006 ),
Array (& quot; deng & quot;,-19003 ),
Array ("di",-18996 ),
Array ("dian",-18977 ),
Array ("diao",-18961 ),
Array (& quot; die & quot;,-18952 ),
Array (& quot; ding & quot;,-18783 ),
Array ("diu",-18774 ),
Array ("dong",-18773 ),
Array ("dou",-18763 ),
Array (& quot; du & quot;,-18756 ),
Array ("duan",-18741 ),
Array (& quot; dui & quot;,-18735 ),
Array ("dun",-18731 ),
Array (& quot; duo & quot;,-18722 ),
Array (& quot; e & quot;,-18710 ),
Array ("en",-18697 ),
Array ("er",-18696 ),
Array (& quot; fa & quot;,-18526 ),
Array ("fan",-18518 ),
Array ("fang",-18501 ),
Array ("fei",-18490 ),
Array ("fen",-18478 ),
Array ("feng",-18463 ),
Array ("fo",-18448 ),
Array ("fou",-18447 ),
Array (& quot; fu & quot;,-18446 ),
Array (& quot; ga & quot;,-18239 ),
Array ("gai",-18237 ),
Array ("gan",-18231 ),
Array ("gang",-18220 ),
Array (& quot; gao & quot;,-18211 ),
Array (& quot; ge & quot;,-18201 ),
Array (& quot; gei & quot;,-18184 ),
Array (& quot; gen & quot;,-18183 ),
Array ("geng",-18181 ),
Array ("gong",-18012 ),
Array ("gou",-17997 ),
Array ("gu",-17988 ),
Array ("gua",-17970 ),
Array ("guai",-17964 ),
Array ("guan",-17961 ),
Array ("guang",-17950 ),
Array (& quot; gui & quot;,-17947 ),
Array ("gun",-17931 ),
Array (& quot; guo & quot;,-17928 ),
Array (& quot; ha & quot;,-17922 ),
Array ("hai",-17759 ),
Array ("han",-17752 ),
Array ("hang",-17733 ),
Array (& quot; hao & quot;,-17730 ),
Array ("he",-17721 ),
Array ("hei",-17703 ),
Array ("bytes",-17701 ),
Array ("heng",-17697 ),
Array ("hong",-17692 ),
Array ("hou",-17683 ),
Array ("hu",-17676 ),
Array ("hua",-17496 ),
Array ("huai",-17487 ),
Array ("huan",-17482 ),
Array ("huang",-17468 ),
Array ("hui",-17454 ),
Array ("hun",-17433 ),
Array ("huo",-17427 ),
Array ("ji",-17417 ),
Array ("jia",-17202 ),
Array (& quot; jian & quot;,-17185 ),
Array ("jiang",-16983 ),
Array ("jiao",-16970 ),
Array ("jie",-16942 ),
Array ("jin",-16915 ),
Array ("jing",-16733 ),
Array ("jiong",-16708 ),
Array ("jiu",-16706 ),
Array ("ju",-16689 ),
Array ("juan",-16664 ),
Array ("jue",-16657 ),
Array ("jun",-16647 ),
Array (& quot; ka & quot;,-16474 ),
Array ("kai",-16470 ),
Array (& quot; kan & quot;,-16465 ),
Array ("kang",-16459 ),
Array ("kao",-16452 ),
Array ("ke",-16448 ),
Array ("ken",-16433 ),
Array (& quot; keng & quot;,-16429 ),
Array ("kong",-16427 ),
Array ("kou",-16423 ),
Array (& quot; ku & quot;,-16419 ),
Array ("kua",-16412 ),
Array ("kuai",-16407 ),
Array ("kuan",-16403 ),
Array ("kuang",-16401 ),
Array ("kui",-16393 ),
Array ("kun",-16220 ),
Array (& quot; kuo & quot;,-16216 ),
Array (& quot; la & quot;,-16212 ),
Array (& quot; lai & quot;,-16205 ),
Array ("lan",-1, 16202 ),
Array (& quot; lang & quot;,-16187 ),
Array (& quot; lao & quot;,-16180 ),
Array (& quot; le & quot;,-16171 ),
Array ("lei",-1, 16169 ),
Array (& quot; leng & quot;,-16158 ),
Array ("li",-16155 ),
Array ("lia",-15959 ),
Array ("lian",-15958 ),
Array ("liang",-15944 ),
Array ("liao",-15933 ),
Array (& quot; lie & quot;,-15920 ),
Array ("lin",-15915 ),
Array (& quot; ling & quot;,-15903 ),
Array ("liu",-15889 ),
Array (& quot; long & quot;,-15878 ),
Array ("lou",-1, 15707 ),
Array ("lu",-15701 ),
Array ("lv",-15681 ),
Array ("luan",-15667 ),
Array ("lue",-15661 ),
Array ("lun",-1, 15659 ),
Array ("luo",-15652 ),
Array ("ma",-15640 ),
Array ("mai",-15631 ),
Array (& quot; man & quot;,-15625 ),
Array (& quot; mang & quot;,-15454 ),
Array (& quot; mao & quot;,-15448 ),
Array (& quot; me & quot;,-15436 ),
Array ("mei",-15435 ),
Array ("men",-15419 ),
Array (& quot; meng & quot;,-15416 ),
Array ("mi",-15408 ),
Array ("mian",-15394 ),
Array ("miao",-15385 ),
Array ("mie",-15377 ),
Array ("min",-15375 ),
Array ("ming",-15369 ),
Array ("miu",-15363 ),
Array ("mo",-15362 ),
Array ("mou",-15183 ),
Array ("mu",-1, 15180 ),
Array ("na",-15165 ),
Array ("nai",-15158 ),
Array (& quot; nan & quot;,-15153 ),
Array ("nang",-15150 ),
Array ("nao",-15149 ),
Array ("ne",-1, 15144 ),
Array ("nei",-15143 ),
Array ("nen",-15141 ),
Array ("neng",-15140 ),
Array ("ni",-15139 ),
Array ("nian",-15128 ),
Array ("niang",-15121 ),
Array ("niao",-15119 ),
Array ("nie",-15117 ),
Array (& quot; nin & quot;,-15110 ),
Array (& quot; ning & quot;,-15109 ),
Array ("niu",-14941 ),
Array (& quot; nong & quot;,-14937 ),
Array (& quot; nu & quot;,-14933 ),
Array (& quot; nv & quot;,-14930 ),
Array ("nuan",-14929 ),
Array ("nue",-14928 ),
Array (& quot; nuo & quot;,-14926 ),
Array (& quot; o & quot;,-14922 ),
Array ("ou",-14921 ),
Array (& quot; pa & quot;,-14914 ),
Array (& quot; pai & quot;,-14908 ),
Array (& quot; pan & quot;,-14902 ),
Array ("pang",-14894 ),
Array (& quot; pao & quot;,-14889 ),
Array ("pei",-1, 14882 ),
Array ("pen",-14873 ),
Array ("peng",-14871 ),
Array ("pi",-1, 14857 ),
Array ("pian",-14678 ),
Array ("piao",-14674 ),
Array ("pie",-14670 ),
Array ("pin",-14668 ),
Array ("ping",-14663 ),
Array ("po",-14654 ),
Array ("pu",-14645 ),
Array (& quot; qi & quot;,-14630 ),
Array ("qia",-14594 ),
Array ("qian",-14429 ),
Array ("qiang",-14407 ),
Array ("qiao",-14399 ),
Array ("qie",-14384 ),
Array ("qin",-14379 ),
Array ("qing",-14368 ),
Array ("qiong",-14355 ),
Array ("qiu",-14353 ),
Array ("qu",-14345 ),
Array ("quan",-14170 ),
Array (& quot; que & quot;,-14159 ),
Array ("qun",-14151 ),
Array ("ran",-14149 ),
Array ("rang",-14145 ),
Array ("rao",-14140 ),
Array ("re",-14137 ),
Array ("ren",-14135 ),
Array (& quot; reng & quot;,-14125 ),
Array ("ri",-14123 ),
Array (& quot; rong & quot;,-14122 ),
Array ("rou",-14112 ),
Array ("ru",-14109 ),
Array ("ruan",-14099 ),
Array ("rui",-14097 ),
Array ("run",-14094 ),
Array ("ruo",-14092 ),
Array (& quot; sa & quot;,-14090 ),
Array ("sai",-14087 ),
Array ("san",-14083 ),
Array ("sang",-13917 ),
Array (& quot; sao & quot;,-13914 ),
Array (& quot; se & quot;,-13910 ),
Array ("sen",-1, 13907 ),
Array (& quot; seng & quot;,-13906 ),
Array (& quot; sha & quot;,-13905 ),
Array ("shai",-13896 ),
Array (& quot; shan & quot;,-13894 ),
Array ("shang",-13878 ),
Array ("shao",-13870 ),
Array ("she",-13859 ),
Array ("shen",-13847 ),
Array ("sheng",-13831 ),
Array ("shi",-13658 ),
Array ("shou",-13611 ),
Array ("shu",-13601 ),
Array (& quot; shua & quot;,-13406 ),
Array ("shuai",-13404 ),
Array ("shuan",-13400 ),
Array ("shuang",-13398 ),
Array ("shui",-13395 ),
Array ("shun",-13391 ),
Array ("shuo",-13387 ),
Array ("si",-1, 13383 ),
Array ("song",-13367 ),
Array ("sou",-13359 ),
Array ("su",-13356 ),
Array ("suan",-13343 ),
Array ("sui",-13340 ),
Array ("sun",-13329 ),
Array (& quot; suo & quot;,-13326 ),
Array (& quot; ta & quot;,-13318 ),
Array ("tai",-13147 ),
Array ("tan",-13138 ),
Array ("tang",-13120 ),
Array ("tao",-13107 ),
Array ("te",-13096 ),
Array ("teng",-13095 ),
Array ("ti",-13091 ),
Array ("tian",-13076 ),
Array ("tiao",-13068 ),
Array ("tie",-13063 ),
Array ("ting",-13060 ),
Array ("tong",-12888 ),
Array ("tou",-12875 ),
Array ("tu",-12871 ),
Array (& quot; tuan & quot;,-12860 ),
Array ("tui",-12858 ),
Array (& quot; tun & quot;,-12852 ),
Array (& quot; tuo & quot;,-12849 ),
Array (& quot; wa & quot;,-12838 ),
Array ("wai",-12831 ),
Array (& quot; wan & quot;,-12829 ),
Array ("wang",-12812 ),
Array ("wei",-12802 ),
Array ("wen",-12607 ),
Array ("weng",-1, 12597 ),
Array ("wo",-12594 ),
Array ("wu",-12585 ),
Array ("xi",-12556 ),
Array (& quot; xia & quot;,-12359 ),
Array ("xian",-12346 ),
Array ("xiang",-12320 ),
Array ("xiao",-12300 ),
Array ("xie",-12120 ),
Array ("xin",-12099 ),
Array ("xing",-12089 ),
Array ("xiong",-12074 ),
Array ("xiu",-12067 ),
Array ("xu",-12058 ),
Array ("xuan",-12039 ),
Array ("xue",-11867 ),
Array ("xun",-11861 ),
Array ("ya",-11847 ),
Array ("yan",-11831 ),
Array ("yang",-11798 ),
Array ("yao",-11781 ),
Array ("ye",-11604 ),
Array ("yi",-11589 ),
Array (& quot; yin & quot;,-11536 ),
Array ("ying",-11358 ),
Array ("yo",-11340 ),
Array (& quot; yong & quot;,-11339 ),
Array (& quot; you & quot;,-11324 ),
Array ("yu",-11303 ),
Array ("yuan",-11097 ),
Array ("yue",-11077 ),
Array (& quot; yun & quot;,-11067 ),
Array (& quot; za & quot;,-11055 ),
Array ("zai",-11052 ),
Array (& quot; zan & quot;,-11045 ),
Array ("zang",-11041 ),
Array ("zao",-11038 ),
Array ("ze",-11024 ),
Array ("zei",-11020 ),
Array ("zen",-11019 ),
Array (& quot; zeng & quot;,-11018 ),
Array (& quot; zha & quot;,-11014 ),
Array ("zhai",-10838 ),
Array ("zhan",-10832 ),
Array ("zhang",-10815 ),
Array ("zhao",-10800 ),
Array ("zhe",-10790 ),
Array ("zhen",-10780 ),
Array ("zheng",-10764 ),
Array (& quot; zhi & quot;,-10587 ),
Array ("zhong",-10544 ),
Array ("zhou",-10533 ),
Array ("zhu",-10519 ),
Array ("zhua",-10331 ),
Array ("zhuai",-10329 ),
Array ("zhuan",-10328 ),
Array ("zhuang",-10322 ),
Array ("zhui",-10315 ),
Array ("zhun",-10309 ),
Array ("zhuo",-10307 ),
Array ("zi",-10296 ),
Array ("zong",-10281 ),
Array (& quot; zou & quot;,-10274 ),
Array ("zu",-10270 ),
Array ("zuan",-10262 ),
Array (& quot; zui & quot;,-10260 ),
Array ("zun",-10256 ),
Array (& quot; zuo & quot;,-10254)
);
Function g ($ num ){
Global $ d;
If ($ num> 0 & $ num <160 ){
Return chr ($ num );
}
Elseif ($ num <-20319 | $ num>-10247 ){
Return "";
} Else {
For ($ I = count ($ d)-1; $ I >=0; $ I --) {if ($ d [$ I] [1] <= $ num) break ;}
Return $ d [$ I] [0];
}
}

Function c ($ str ){
$ Ret = "";
For ($ I = 0; $ I $ P = ord (substr ($ str, $ I, 1 ));
If ($ p & gt; 160 ){
$ Q = ord (substr ($ str, ++ $ I, 1 ));
$ P = $ p * 256 + $ q-65536;
}
$ Ret. = g ($ p );
}
Return $ ret;
}
 
Echo c ($ hz );
?>

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.