PHP Kanji to Pinyin

Source: Internet
Author: User



<?PHP
chinese_to_abc.class.phpclassChinesespell {//Note Support only: GBK, so the pass-through code must be transferred before the parameter /** * @var array $chineseSpellList phonetic encoding corresponding table * @access private*/ Private $chineseSpellList=Array( ' A ' =>-20319, ' ai ' =>-20317, ' an ' =>-20304, ' ang ' =>-20295, ' ao ' =>-20292, ' ba ' =>-20283, ' B Ai ' =>-20265, ' ban ' =>-20257, ' bang ' =>-20242, ' bao ' =>-20230, ' bei ' =>-20051, ' Ben ' =>-20036, ' Beng ' =>-20032, ' bi ' =>-20026, ' Bian ' =>-20002, ' Biao ' =>-19990, ' Bie ' =>-19986, ' bin ' =>-1 9982, ' Bing ' =>-19976, ' bo ' =>-19805, ' bu ' =>-19784, ' Ca ' =>-19775, ' cai ' =>-19774, ' can ' = -19763, ' Cang ' =>-19756, ' Cao ' =>-19751, ' CE ' =>-19746, ' CEng ' =>-19741, ' Cha ' =>-19739, ' chai ' =>-19728, ' Chan ' =>-19725, ' Chang ' =>-19715, ' Chao ' =>-19540, ' che ' =>-19531, ' Chen ' =>-19525 , ' Cheng ' =>-19515, ' chi ' =>-19500, ' Chong ' =>-19484, ' Chou ' =>-19479, ' Chu ' =>-19467, ' Chuai ' =>-19289, ' Chuan ' =>-19288, ' Chuang ' =>-19281, ' Chui ' =>-19275, ' Chun ' =>-19270, ' Chuo ' =>-192 The ' CI ' =>-19261, ' Cong ' =>-19249, ' cou ' =>-19243, ' cu ' =>-19242, ' Cuan ' =>-19238, ' cui ' =>-19235, ' Cun ' =>-19 227, ' CuO ' =>-19224, ' da ' =>-19218, ' dai ' =>-19212, ' Dan ' =>-19038, ' dang ' =>-19023, ' DAO ' =&gt ; -19018, ' de ' =>-19006, ' Deng ' =>-19003, ' di ' =>-18996, ' dian ' =>-18977, ' Diao ' =>-18961, ' die ' =>-18952, ' ding ' =>-18783, ' Diu ' =>-18774, ' Dong ' =>-18773, ' dou ' =>-18763, ' du ' =>-18756, ' Duan ' =>-18741, ' DUI ' =>-18735, ' dun ' =>-18731, ' duo ' =>-18722, ' e ' =>-18710, ' en ' =>-18697, ' Er ' =>-18696, ' fa ' =>-18526, ' fan ' =>-18518, ' Fang ' =>-18501, ' Fei ' =>-18490, ' fen ' =>-1847 8, ' Feng ' =>-18463, ' fo ' =>-18448, ' fou ' =>-18447, ' Fu ' =>-18446, ' ga ' =>-18239, ' Gai ' =>-18 237, ' gan ' =>-18231, ' gang ' =>-18220, ' Gao ' =>-18211, ' ge ' =>-18201, ' GEi ' =>-18184, ' gen ' =&gt ; -18183, ' Geng ' =>-18181, ' Gong ' =>-18012, ' Gou ' =>-17997, ' gu ' =>-17988, ' gua ' =>-17970, ' Guai ' =>-17964, ' Guan ' =>-17961, ' Guang ' =>-17950, ' GUI ' =>-17947, ' gun ' =>-17931, ' Guo ' =>-17928, ' ha ' =>-17922, ' Hai ' =>-17759, ' Han ' =>-17752, ' Hang ' =>-17733, ' Hao ' =>-17730, ' he ' =>-17721, ' Hei ' =>-17703, ' Hen ' =>-17701, ' Heng ' =>-17697, ' Hong ' =>-17692, ' Hou ' =>-17683, ' Hu ' =>-17676, ' Hua ' =>-1 7496, ' Huai ' =>-17487, ' Huan ' =>-17482, ' Huang ' =>-17468, ' hui ' =>-17454, ' Hun ' =>-17433, ' Huo ' =>-17427, ' Ji ' =>-17417, ' Jia ' =>-17202, ' Jian ' =>-17185, ' Jiang ' =>-16983, ' jiao ' =>-16970, ' Jie ' =>-16942, ' Jin ' =>-16915, ' Jing ' =>-16733, ' Jiong ' =>-16708, ' JIU ' =>-16706, ' Ju ' =>-1 6689, ' Juan ' =>-16664, ' Jue ' =>-16657, ' June ' =>-16647, ' ka ' =>-16474, ' kai ' =>-16470, ' kan ' =&G t;-16465, ' kang ' =-16459, ' kao ' =>-16452, ' ke ' =>-16448, ' Ken ' =>-16433, ' Keng ' =>-16429, ' Kong ' =>-16427, ' Kou ' =>-16423, ' Ku ' =>-16419, ' Kua ' =>-16412, ' Kuai ' =>-16407, ' Kuan ' =>-16403, ' Kuang ' =>-16401, ' Kui ' =>-16393, ' Kun ' =>-16220, ' Kuo ' =>-16216, ' La ' =>-16212, ' Lai ' =>-16205, ' LAN ' =>-16202 , ' Lang ' =>-16187, ' Lao ' =>-16180, ' Le ' =>-16171, ' lei ' =>-16169, ' Leng ' =>-16158, ' Li ' =>-1 6155, ' Lia ' =>-15959, ' Lian ' =>-15958, ' Liang ' =>-15944, ' Liao ' =>-15933, ' lie ' =>-15920, ' Lin ' =>-15915, ' ling ' =>-15903, ' Liu ' =>-15889, ' long ' =>-15878, ' Lou ' =>-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 ' =>-15 435, ' Men ' =>-15419, ' Meng ' =>-15416, ' mi ' =>-15408, ' Mian ' =>-15394, ' Miao ' =>-15385, ' mie ' =>-15377, ' min ' = -15375, ' Ming ' =>-15369, ' Miu ' =>-15363, ' Mo ' =>-15362, ' mou ' =>-15183, ' mu ' =>-15180, ' na ' =&G t;-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, ' nie ' =>-15117, ' nin ' =>-15110, ' ning ' =>-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 ' =& gt;-14889, ' Pei ' =>-14882, ' pen ' =>-14873, ' Peng ' =>-14871, ' pi ' =>-14857, ' Pian ' =>-14678, ' p Iao ' =>-14674, ' pie' =>-14670, ' pin ' =>-14668, ' ping ' =>-14663, ' po ' =>-14654, ' pu ' =>-14645, ' qi ' =>-14630, ' Q Ia ' =>-14594, ' Qian ' =>-14429, ' Qiang ' =>-14407, ' Qiao ' =>-14399, ' qie ' =>-14384, ' Qin ' =>-1437 9, ' Qing ' =>-14368, ' Qiong ' =>-14355, ' Qiu ' =>-14353, ' qu ' =>-14345, ' Quan ' =>-14170, ' que ' =&G t;-14159, ' Qun ' =>-14151, ' ran ' =>-14149, ' rang ' =>-14145, ' Rao ' =>-14140, ' re ' =>-14137, ' ren ' =>-14135, ' Reng ' =>-14125, ' ri ' =>-14123, ' Rong ' =>-14122, ' Rou ' =>-14112, ' ru ' =>-14109, ' Ruan ' =>-14099, ' Rui ' =>-14097, ' run ' =>-14094, ' Ruo ' =>-14092, ' sa ' =>-14090, ' Sai ' =>-14087, ' San ' =>-14083, ' sang ' =>-13917, ' Sao ' =>-13914, ' se ' =>-13910, ' sen ' =>-13907, ' Seng ' =>-1 3906, ' Sha ' =>-13905, ' Shai ' =>-13896, ' Shan ' =>-13894, ' Shang ' =>-13878, ' Shao ' =>-13870, ' sh E ' =>-13859, ' shen '=>-13847, ' Sheng ' =>-13831, ' Shi ' =>-13658, ' Shou ' =>-13611, ' Shu ' =>-13601, ' Shua ' =>-13406, ' Shuai ' =>-13404, ' Shuan ' =>-13400, ' Shuang ' =>-13398, ' Shui ' =>-13395, ' Shun ' =>-13391, ' Shuo ' =>-13387, ' si ' =>-13383, ' song ' =>-13367, ' sou ' =>-13359, ' su ' =>-13356, ' Suan ' =>-13343, ' Sui ' =>-13340, ' Sun ' =>-13329, ' suo ' =>-13326, ' ta ' =>-13318, ' Tai ' =>-13147, ' tan ' =>-13138, ' Tang ' =>-13120, ' Tao ' =>-13107, ' te ' =>-13096, ' teng ' =>-13095, ' ti ' =>-13091, ' Tian ' =>-13 076, ' Tiao ' =>-13068, ' tie ' =>-13063, ' ting ' =>-13060, ' Tong ' =>-12888, ' tou ' =>-12875, ' tu ' =& gt;-12871, ' Tuan ' =>-12860, ' tui ' =>-12858, ' tun ' =>-12852, ' Tuo ' =>-12849, ' wa ' =>-12838, ' WA I ' =>-12831, ' Wan ' =>-12829, ' Wang ' =>-12812, ' Wei ' =>-12802, ' Wen ' =>-12607, ' Weng ' =>-12597, ' Wo ' =>-12594, 'Wu ' =>-12585, ' XI ' =>-12556, ' Xia ' =>-12359, ' Xian ' =>-12346, ' Xiang ' =>-12320, ' Xiao ' =>-12300 , ' Xie ' =>-12120, ' Xin ' =>-12099, ' Xing ' =>-12089, ' Xiong ' =>-12074, ' Xiu ' =>-12067, ' xu ' = -12058, ' Xuan ' =>-12039, ' Xue ' =>-11867, ' Xun ' =>-11861, ' ya ' =>-11847, ' Yan ' =>-11831, ' Yang ' =>-11798, ' Yao ' =>-11781, ' ye ' =>-11604, ' Yi ' =>-11589, ' Yin ' =>-11536, ' Ying ' =>-11358, ' Y O ' =>-11340, ' Yong ' =>-11339, ' You ' =>-11324, ' Yu ' =>-11303, ' yuan ' =>-11097, ' Yue ' =>-11077, ' Yun ' =>-11067, ' za ' =>-11055, ' Zai ' =>-11052, ' Zan ' =>-11045, ' Zang ' =>-11041, ' Zao ' =>-1103 8, ' ze ' =>-11024, ' Zei ' =>-11020, ' Zen ' =>-11019, ' Zeng ' =>-11018, ' Zha ' =>-11014, ' zhai ' = -10838, ' Zhan ' =>-10832, ' Zhang ' =>-10815, ' Zhao ' =>-10800, ' Zhe ' =>-10790, ' zhen ' =>-10780, ' Zheng ' =>-10764, ' ZHi ' =>-10587, ' Zhong ' =>-10544, ' Zhou ' =>-10533, ' Zhu ' =>-10519, ' Zhua ' =>-10331, ' Zhuai ' =>-10 329, ' Zhuan ' =>-10328, ' Zhuang ' =>-10322, ' Zhui ' =>-10315, ' Zhun ' =>-10309, ' Zhuo ' =>-10307, ' Zi ' =>-10296, ' Zong ' =>-10281, ' Zou ' =>-10274, ' zu ' =>-10270, ' Zuan ' =>-10262, ' Zui ' =>-10260, ' Zun ' =>-10256, ' Zuo ' =>-10254 ); /** * Take Chinese characters all pinyin * @param string $chinese the kanji to be converted * @param string $delimiter delimiter * @param int $length The returned length * @return String*/ Public functionGetfullspell ($chinese,$delimiter= ",$length= 0){ $spell=$this->getchinesespells ($chinese,$delimiter); if($length){ $spell=substr($spell, 0,$length); } return $spell; } /** * Take kanji "one" Chinese character complete pinyin * @param string $chinese the kanji to be converted * @param int $length The length returned * @return string*/ Public functionGetfirstspell ($chinese,$length= 0){ $spell=$this->getchinesespells ($chinese, ", 1); if($length){ $spell=substr($spell, 0,$length); } return $spell; } /** * Take a Chinese character code corresponding pinyin * @param int $num Kanji code * @param string $blank white space character * @return string*/ Public functionGetchinesespell ($num,$blank= ' '){ if($num>0 &&$num<160){ return CHR($num); } ElseIf($num<-20319| |$num>-10247){ return $blank; } Else{ foreach($this->chinesespelllist as $spell=$code){ if($code>$num) Break; $result=$spell; } return $result; } } /** take Chinese pinyin * @param string $chinese the kanji to be converted * @param string $delimiter delimiter * @param int $first returns only the first * @return String*/ Public functionGetchinesespells ($chinese,$delimiter= ",$first=0){ $result=Array(); for($i= 0;$i<strlen($chinese);$i++){ $p=Ord(substr($chinese,$i, 1)); if($p>160){ $q=Ord(substr($chinese,++$i, 1)); $p=$p*256 +$q-65536; } $result[] =$this->getchinesespell ($p); if($first){ return $result[0]; } } return implode($delimiter,$result); }}?>
        require_once(' chinese_to_abc.class.php '); $ok=NewChinesespell (); $str _utf8= "Who Are you?"; $str _gb2312=Iconv("UTF-8", "Gb2312//ignore",$str _utf8) ; $str _full=$ok->getfullspell ($str _gb2312); $str _array=Str_split($str _utf8, 3); foreach($str _array  as $key=$value )        {            $value=Iconv("UTF-8", "Gb2312//ignore",$value) ; $str _first.=$ok->getfirstspell ($value, 1); }        Echo"Chinese character &nbsp;".$str _utf8; Echo"<br/>"; Echo"Full spell &nbsp;".$str _full; Echo"<br/>"; Echo"First Letter &nbsp;".$str _first;  die();

PHP Kanji to Pinyin

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.