php程序中如何调用汉字转换成拼音的方法

$source?=?“中国”;

$aim?=?新的?cut F8 _ PY();

回声?$aim?-& gt;?编码(?$source?,?head’);

回声?”\ r \ n”;

回声?$aim?-& gt;?编码(?$source?,?all’);

/**

*?PHP?汉字转拼音

*?@作者?Jerryli(hzjerry@gmail.com)

*?@版本?V0.20140715

*?@包?SPFW.core.lib.final

*?@全球?海洋_PHP_FW_VAR_ENV

*?@示例

*回声?CUtf8_PY::encode('阿里巴巴科技有限公司');?//代码是拼音首字母。

*回声?CUtf8_PY::encode('阿里巴巴科技有限公司',?all’);?//代码是全拼音。

*/

班级?CUtf8_PY?{

/**

?*?拼音字符转换图

?*?@var?排列

?*/

私人?静电?$_aMaps?=?数组(

a ' = & gt-20319,' ai ' = & gt-20317,'安' = & gt-20304,' ang ' = & gt-20295,' ao ' = & gt-20292,

ba ' = & gt-20283,'白' = & gt-20265,' ban ' = & gt-20257,'砰' = & gt-20242,'宝' = & gt-20230,'贝' = & gt-20051,' ben ' = & gt-20036,' beng ' = & gt-20032,' bi ' = & gt-20026,'边' = & gt-20002,'彪' = & gt-19990,' bie ' = & gt-19986,' bin ' = & gt-19982,'冰' = & gt-19976,' bo ' = & gt-19805,' bu ' = & gt-19784,

ca ' = & gt-19775,'蔡' = & gt-19774,'可以' = & gt-19763,'仓' = & gt-19756,'曹' = & gt-19751,' ce ' = >;-19746,'曾' = & gt-19741,' cha ' = & gt-19739,'柴' = & gt-19728,' chan'= >-19725,' chang ' = & gt-19715,'超' = & gt-19540,' che ' = & gt-19531,'陈' = & gt-19525,'程' = & gt-19515,'池' = >;-19500,'冲' = & gt-19484,' chou ' = & gt-19479,'楚' = & gt-19467,'揣' = & gt-19289,'川' = & gt-19288,'创' = & gt-19281,' chui ' = & gt-19275,'春' = & gt-19270,' chuo ' = & gt-19263,' ci ' = & gt-19261,'丛' = >;-19249,' cou ' = & gt-19243,' cu ' = & gt-19242,' cuan ' = & gt-19238,'崔' = & gt-19235,' cun ' = & gt-19227,' cuo ' = & gt-19224,

da ' = & gt-19218,'戴' = >;-19212,'丹' = >;-19038,' dang ' = & gt-19023,'道' = & gt-19018,' de ' = >;-19006,'邓' = & gt-19003,' di ' = & gt-18996,' dian ' = & gt-18977,'刁' = & gt-18961,' die ' = & gt-18952,'丁' = & gt-18783,' diu ' = & gt-18774,' dong ' = & gt-18773,'窦' = & gt-18763,' du ' = & gt-18756,'段' = & gt-18741,' dui ' = & gt-18735,' dun ' = & gt-18731,' duo ' = & gt-18722,

e ' = & gt-18710,' en ' = >;-18697,' er ' = & gt-18696,

fa ' = & gt-18526,'范' = & gt-18518,'方' = >;-18501,'费' = & gt-18490,' fen ' = & gt-18478,'冯' = & gt-18463,' fo ' = & gt-18448,' fou ' = & gt-18447,'傅' = & gt-18446,

ga ' = & gt-18239,' gai ' = & gt-18237,'甘' = & gt-18231,' gang ' = & gt-18220,'高' = & gt-18211,' ge ' = & gt-18201,' gei ' = >;-18184,' gen ' = >;-18183,'庚' = & gt-18181,'宫' = & gt-18012,' Gou ' = >;-17997,'顾' = & gt-17988,'瓜' = & gt-17970,'怪' = & gt-17964,'关' = & gt-17961,'广' = >;-17950,' gui ' = & gt-17947,'枪' = & gt-17931,'郭' = >;-17928,

哈' = & gt-17922,'海' = & gt-17759,'韩' = & gt-17752,'挂' = & gt-17733,'郝' = & gt-17730,'他' = & gt-17721,'黑' = >;-17703,' hen ' = & gt-17701,'恒' = >;-17697,'洪' = & gt-17692,'侯' = & gt-17683,'胡' = & gt-17676,'华' = & gt-17496,'淮' = & gt-17487,'欢' = & gt-17482,'黄' = & gt-17468,'惠' = & gt-17454,' hun ' = & gt-17433,'霍' = & gt-17427,

ji ' = & gt-17417,'贾' = & gt-17202,'建' = & gt-17185,'江' = & gt-16983,'焦' = & gt-16970,'杰' = & gt-16942,'金' = & gt-16915,'京' = & gt-16733,'炯' = & gt-16708,'九' = & gt-16706,' ju ' = & gt-16689,'胡安' = & gt-16664,'爵' = & gt-16657,'君' = & gt-16647,

ka ' = & gt-16474,' kai ' = & gt-16470,' kan ' = & gt-16465,'康' = & gt-16459,' kao ' = & gt-16452,' ke ' = & gt-16448,' ken ' = & gt-16433,' keng ' = & gt-16429,'孔' = & gt-16427,' kou ' = & gt-16423,' ku ' = & gt-16419,' kua ' = >;-16412,'快' = >;-16407,'宽' = & gt-16403,'匡' = & gt-16401,'奎' = & gt-16393,' kun ' = & gt-16220,' kuo ' = & gt-16216,

la ' = & gt-16212,'赖' = >;-16205,'兰' = & gt-16202,'郎' = & gt-16187,'老' = & gt-16180,'了' = >;-16171,'雷' = & gt-16169,'冷' = >;-16158,'李' = >;-16155,' lia ' = >;-15959,'连' = & gt-15958,'梁' = & gt-15944,'廖' = & gt-15933,' lie ' = & gt-15920,'林' = & gt-15915,'凌' = & gt-15903,'刘' = & gt-15889,' long ' = & gt-15878,'楼' = & gt-15707,'卢' = & gt-15701,' lv ' = & gt-15681,'栾' = >;-15667,' lue ' = & gt-15661,' lun ' = & gt-15659,'罗' = & gt-15652,

ma ' = & gt-15640,' mai ' = & gt-15631,' man ' = & gt-15625,' mang ' = & gt-15454,'毛' = & gt-15448,'我' = & gt-15436,'梅' = & gt-15435,'男人' = & gt-15419,'孟' = >;-15416,' mi ' = >;-15408,' mian ' = >;-15394,'苗' = & gt-15385,' mie ' = & gt-15377,' min ' = & gt-15375,'明' = & gt-15369,' miu ' = & gt-15363,' mo ' = & gt-15362,' mou ' = & gt-15183,' mu ' = & gt-15180,

na ' = & gt-15165,'奈' = >;-15158,' nan ' = & gt-15153,' nang ' = >;-15150,' nao ' = & gt-15149,' ne ' = >;-15144,' nei ' = >;-15143,' nen ' = & gt-15141,'能' = & gt-15140,' ni ' = >;-15139,'年' = >;-15128,'娘' = & gt-15121,'鸟' = & gt-15119,'聂' = >;-15117,' nin ' = >;-15110,'宁' = >;-15109,'牛' = & gt-14941,'农' = >;-14937,' nu ' = & gt-14933,' nv ' = & gt-14930,' nuan ' = & gt-14929,' nue ' = & gt-14928,'诺' = & gt-14926,

o ' = & gt-14922,' ou ' = & gt-14921,

pa ' = & gt-14914,' pai ' = >;-14908,'潘' = & gt-14902,'庞' = & gt-14894,' pao ' = & gt-14889,'裴' = & gt-14882,'笔' = & gt-14873,'彭' = & gt-14871,' pi ' = >;-14857,' pian ' = & gt-14678,'飘' = & gt-14674,'馅饼' = & gt-14670,' pin ' = & gt-14668,' ping ' = & gt-14663,' po ' = & gt-14654,' pu ' = & gt-14645,

齐' = & gt-14630,' qia ' = & gt-14594,'钱' = & gt-14429,' qiang ' = & gt-14407,'乔' = & gt-14399,' qie ' = & gt-14384,'秦' = & gt-14379,'清' = & gt-14368,'琼' = & gt-14355,'邱' = & gt-14353,'曲' = & gt-14345,'全' = & gt-14170,' que ' = >;-14159,'群' = >;-14151,

ran ' = & gt-14149,' rang ' = & gt-14145,'饶' = & gt-14140,' re ' = >;-14137,'任' = >;-14135,' reng ' = >;-14125,' ri ' = >;-14123,'荣' = & gt-14122,'柔' = >;-14112,' ru'= >-14109,'阮' = >;-14099,'瑞' = & gt-14097,' run ' = & gt-14094,'若' = & gt-14092,

sa ' = & gt-14090,' sai ' = & gt-14087,' san ' = & gt-14083,'桑' = & gt-13917,'骚' = & gt-13914,' se ' = >;-13910,' sen ' = >;-13907,' seng ' = & gt-13906,' sha ' = & gt-13905,' shai ' = & gt-13896,'山' = & gt-13894,'尚' = & gt-13878,'邵' = & gt-13870,'她' = & gt-13859,'沈' = & gt-13847,'盛' = & gt-13831,'石' = >;-13658,'寿' = & gt-13611,'舒' = >;-13601,' shua ' = & gt-13406,'帅' = & gt-13404,' shuan ' = & gt-13400,'爽' = & gt-13398,'水' = & gt-13395,'顺' = & gt-13391,'说' = & gt-13387,' si ' = & gt-13383,'宋' = & gt-13367,' sou ' = & gt-13359,'苏' = & gt-13356,' suan ' = & gt;-13343,'隋' = >;-13340,'孙' = & gt-13329,'索' = & gt-13326,

ta ' = & gt-13318,'泰' = >;-13147,'谭' = >;-13138,'唐' = & gt-13120,'陶' = & gt-13107,' te ' = >;-13096,'滕' = & gt-13095,' ti ' = & gt-13091,'田' = & gt-13076,'条' = & gt-13068,' tie ' = & gt-13063,' ting ' = & gt-13060,'童' = & gt-12888,' tou ' = & gt-12875,' tu ' = & gt-12871,' Tuan ' = >;-12860,' tui ' = & gt-12858,' tun ' = & gt-12852,'陀' = & gt-12849,

wa ' = & gt-12838,'围' = & gt-12831,'万' = >;-12829,'王' = & gt-12812,'魏' = & gt-12802,'文' = & gt-12607,'翁' = & gt-12597,' wo ' = & gt-12594,'吴' = & gt-12585,

Xi ' = & gt;-12556,'夏' = & gt-12359,'西安' = & gt-12346,'向' = & gt-12320,'肖' = & gt-12300,'谢' = & gt-12120,' Xin ' = >;-12099,' xing ' = & gt-12089,'熊' = & gt-12074,'秀' = & gt-12067,'徐' = & gt-12058,'宣' = & gt-12039,'薛' = & gt-11867,'荀' = & gt-11861,

ya ' = & gt-11847,'颜' = & gt-11831,'杨' = & gt-11798,'姚' = & gt-11781,' ye ' = >;-11604,'易' = & gt-11589,'尹' = >;-11536,'英' = >;-11358,' yo ' = & gt-11340,'勇' = & gt-11339,'你' = & gt-11324,'于' = & gt-11303,'袁' = & gt-11097,'岳' = & gt-11077,'云' = >;-11067,

za ' = & gt-11055,' zai ' = & gt-11052,' zan ' = & gt-11045,'臧' = >;-11041,' Zao ' = >;-11038,' ze ' = >;-11024,' zei ' = & gt-11020,'禅' = & gt-11019,'曾' = & gt-11018,'扎' = & gt-11014,'翟' = & gt-10838,'詹' = & gt-10832,'张' = & gt-10815,'赵' = & gt-10800,' zhe ' = & gt-10790,'真' = & gt-10780,'郑' = & gt-10764,'智' = & gt-10587,'钟' = & gt-10544,'周' = & gt-10533,'朱' = & gt-10519,' zhua ' = >;-10331,'追' = >;-10329,'转' = & gt-10328,'庄' = & gt-10322,'追' = & gt-10315,'准' = >;-10309,'卓' = & gt-10307,'子' = & gt-10296,'宗' = & gt-10281,'邹' = & gt-10274,' zu ' = & gt-10270,'安祖' = & gt-10262,' zui ' = & gt-10260,'尊' = & gt-10256,'左' = & gt-10254

);

/**

*?将中文编码成拼音

*?@param?字符串?$utf8Data?Utf8字符集数据

*?@param?字符串?$sRetFormat?返回格式?[head:声母|all:全拼音]

*?@回归?线

*/

公?静电?功能?encode($utf8 data,?$sRetFormat='head'){

$sGBK?=?iconv('UTF-8 ',?GBK的?$ utf8 data);

$aBuf?=?array();

为了什么?($i=0,?$ iLoop = strlen($ sGBK);?$ i & lt$ iLoop?$i++)?{

$iChr?=?ord($ sGBK { $ I });

如果?($ iChr & gt160)

$iChr?=?($ iChr & lt& lt8)?+?ord($sGBK{++$i})?-?65536;

如果?(‘头’?===?$sRetFormat)

$aBuf[]?=?substr(self::zh2py($iChr),0,1);

其他

$aBuf[]?=?self::zh2py($ iChr);

}

如果?(‘头’?===?$sRetFormat)

回归?内爆('',?$ aBuf);

其他

回归?内爆('?',?$ aBuf);

}

/**

?*?将中文转换为拼音(一次一个字符)

?*?@param?号码?$iWORD?要处理的双字节字符

?*?@回归?字符串?拼写

?*/

私人?静电?功能?zh2py($iWORD)?{

if($I word & gt;0?& amp& amp?$ iWORD & lt160?)?{

回归?chr($ iWORD);

}?埃尔瑟夫?($ iWORD & lt-20319 | | $ iWORD & gt;-10247)?{

回归?'';

}?不然呢?{

foreach?(self::$_aMaps?作为?$py?= & gt?$code)?{

如果($码?& gt?$iWORD)?打破;

$结果?=?$ py

}

回归?$ result

}

}

}/hzbigdog/文章/详情/37817135