function Pinyin($_String, $_Code='UTF8'){ //GBK頁面可改為gb2312,其他隨意填入UTF8
$_DataKey = "a|ai|an|ang|ao|ba| bai|ban|bang|bao|bei|ben|beng|bi|bian|biao|bie|bin|bing|bo|bu|ca|cai|can|cang|cao|ce|ceng|cha".
"|chai|chan|chang|chao|che|chen|cheng|chi|chong|chou|chu|chuai|chuan|chuang|chui|chun|chuo|ci|cong|cou|cu|".
cuan|cui|cun|cuo|da|dai|dan|dang|dao|de|deng|di|dian|diao|die|ding|diu|dong|dou|du|duan|dui|dun|duo|e| en|er".
"|fa|fan|fang|fei|fen|feng|fo|fou|fu|ga|gai|gan|gang|fei|fen|feng|fo|fou|fu|ga|gai|gan|gang|gao|ge|gei| gu|gua|guai|guan|guang|gui".
"|gun|guo|ha|hai|han|hang|hao|he|hei|hou* huan|huang|hui|hun|huo|ji|jia|jian|jiang".
"|jiao|jie|jin|jing|jiong|jiu|ju; kang|kao|ke|ken|keng|kong|kou|ku|kua|kuai|kuan|kuang".
"|kui|kuno|lalang| leng|li|lia|lian|liang|liao|lie|lin|ling|liu|long|lou|lu|lv|luan|lue".
"|lun|luoman|mai| mao|me|mei|men|meng|mi|mian|miao|mie|min|ming|miu|mo|mou|mu|na|nai|nan|nang|nao|ne".
" nen|neng|ni|nian|niang|niao|nie|nin|ning|niu|nong|nu|nv|nuan|nue|nuo|o|ou|pa|pai|pan|pang|pao|pei|pen" .
"|peng|pi|pian|piao|pie|pin|ping|po|pu|qi|qia|qian|qiang|qiao|y|pin|ping| qun|ran|rang".
"|rao|re|ren|reng|ri|rong|rou|ru|ruan|rui|runai|ruo|sa|ren|reng|ri|rong|rou|ru|ruan|rui|runai|ruo|sa|sao | seng|sha|shai|shan|shang|shao|".
"she|shen|sheng|shi|shou|shu|shua|shuai|shuanan|shuan|sheng|shi|shou|shu|shua|shuai|shuan|shuans| su|suan|sui|sun|suo|ta|tai|".
"tan|tang|tao|te|teng|ti|tian|tiao|tie|ting|tong|tang|tao|te|teng|ti|tian|tiao|tie|ting| tun|tuo|wa|wai|wan|wang|wei|wen|weng|wo|wu".
"|xi|xia|xian|xiang|xiao|xie|xin|xia|xian|xiang|xiao|xie|xin|xia|xian| xuan|xue|xun|ya|yan|yang|yao|ye|yi|yin|ying|yo|yong|you".
"|yu|yuan|yue|y|za| zao|ze|zei|zen|zeng|zha|zhai|zhan|zhang|zhao|zhe|zhen|zheng|zhi|zhong|".
zhun|zhuo|zi|zong|zou|zu|zuan|zui|zun|zuo";
$_DataValue = "-20319|-20317|-20304|-20295|-20292|-202853| 20257|-20242|-20230|-20051|-20036|-20032|-20026|-20002|-19990".
76|-19805|-19784|-19775| -19774|-19763|-19756|-19751|-19746|-19741|-19739|-19728|-19725".
31|-19525|-19515|-19500 |-19484|-19479|-19467|-19289|-19288|-19281|-19275|-19270|-19263".
243|-19242|-19238|- 19235|-19227|-19224|-19218|-19212|-19038|-19023|-19018|-19006|-19003". ## 77|-18961|-18952|-18783| -18774|-18773|-18763|-18756|-18741|-18735|-18731|-18722|-18710|-18697". ## 18710|-18697". ## 26|-18518|-18501|-18490 |-18478|-18463|-18448|-18447|-18446|-18239|-18237|-18231|-18220|-18211"。 184|-18183|-18181|- 18012|-17997|-17988|-17970|-17964|-17961|-17950|-17947|-17931|-17928|-17922".
“|-17759|-17752|-17733|-17730|-17721|-17703|-17701|-17697|-17692|-17683|-17676|-17496|-17487|887|
16706|-166 89|-16664 " 。
16419|-164 12|-16407 " 。
16158|-161 55|-15959 " 。
15661|-156 59|-15652 " 。
15377|-153 75|-15369 " 。
15140|-151 39|-15128 " 。
14922|-149 21|-14914 " 。
14663|-146 54|-14645 " 。
14159|-141 51|-14149 " 。
14092|-140 90|-14087 " 。
13847|-138 31|-13658 " 。
13356|-133 43|-13340 " 。
13063|-130 60|-12888 " 。
與 12597|-125 94|-12585 " 。
11867|-118 61|-11847 " 。
11077|-110 67|-11055 " 。
10800|-107 90|-10780 " 。
10296|-102 81|-10274 " 。
「|-10270|-10262|-10260|-10256|-10254」;
$_TDataKey = 爆炸('|', $_DataKey);
$_TDataValue = Explode('|', $_DataValue);
$_Data = array_combine($_TDataKey, $_TData
重置($_Data);
if($_Code!= 'gb2312') $_String = _U2_Utf8_Gb($_String);
$_Res = '';
for($i=0; $i
if($_P>160) {
$_Q = ord(sub++($1,),$ $_P = $_P*256 + $_Q - 65536;
}
$_Res .= _Pinyin($_P, $_Data);
}
return preg_replace("/[^a-z0-9]*/", '', $_Res);
}
function _Pinyin($_Num, $_Data){
if($_Num>0 && $_Num $ _Num-10247){
return '';
# }else{
=$ _Num ) 中斷; }
返回 $k;
}
}
function _U2_Utf8_Gb($_C){
$_String = '';
if($_C $_String .= $_C;
c}elseif($_C) >> ; 6);
$_String .= chr(0x80 | $_C & 0x3F);
}elseif($_C $_String .= chr(0xE0 | $_C>>12);
$_String .= chr(0x80 | $_C>>6 & 0x3F);
$_String .= chr(0x80 | $_C & 0x3F);
}elseif($_C $_String .= chr(0xF0 | $_C>>18);
$_String .= chr(0x80 | $_C>>12 & 0x3F);
$_String .= chr(0x80 | $_C>>6 & 0x3F);
$_String .= chr(0x80 | $_C & 0x3F);
}
return iconv('UTF-8', 'GB2312', $_String);
}
//測試
以上是php函數--漢子轉拼音函數的詳細內容。更多資訊請關注PHP中文網其他相關文章!