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|gao|ge|gei|gen|geng|gong|gou|gu|gua|guai| guan|guang|gui".
"|gun|guo|ha|hai|han|hang|hao|he|hei|hen|heng|hong|hou|hu|hua|huai|huan|huang|hui|hun| huo|ji| jia|jian|jiang".
" ku|kua|kuai|kuan|kuang".
"|kui|kun|kuo|la|lai|lan|lang|lao|le|lei|leng|li |lia|lian|liang|liao|lie|lin| ling|liu|long|lou|lu|lv|luan|lue". "|lun|luo|ma|mai|man|mang|mao|me|mei| men|meng|mi|mian|miao|mie| min|ming|miu|mo|mou|mu|na|nai|nan|nang|nao|ne"."|nei|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|qie|qin|qing|qiong|qiu|qu|quan|que|qun|ran|rang".
" "| rao|re|ren|reng|ri|rong|rou|ru|ruan|rui|run|ruo|sa|sai|san|sang|sao|se|sen|seng|sha|shai|shan|shang|shao| ".
"she|shen|sheng|shi| shou|shu|shua|shuai|suan|shuang|shui|shun|shuo|si|song|sou|su|suan|sui|sun|suo|ta|tai| ".
"tan|tang|tao|te|teng|ti|tian|tiao|tie|ting|tong|tou|tu|tuan|tui|tun|tuo|wa|wai|wan|wang|wei|wen| weng|wo|wu". "|xi| xia|xian|xiang|xiao|xie|xin|xing|xiong|xiu|xu|xuan|xue|xun|ya|yan|yang|yao|ye|yi|yin |ying|yo|yong|you".
"|yu|yuan|yue|yun|za|zai|zan|zang|zao|ze|zei|zen|zeng|zha|zhai|zhan|zhang|zhao|zhe |zhen|zheng|zhi|zhong|".
"zhou|zhu|zhua|zhuai|zhuan|zhuang|zhui|zhun|zhuo|zi|zong|zou|zu|zuan|zui|zun|zuo";
$ _DataValue = "-20319|-20317|-2030 4 |-20295|-20292|-20283|-20265|-20257|-20242|-20230|-20051|-20036|-20032|-20026|-20002|- 19990".
" |-19986|-19982| -19976|-19805|-19784|-19775|-19774|-19763|-19756|-19751|-19746|-19741|-19739|-19728|-19725 ". -19715|-19540|- 19531|-19525|-19515|-19500|-19484|-19479|-19467|-19289|-19288|-19281|-19275|-19270|-19263". |-19249|-19243 |-19242|-19238|-19235|-19227|-19224|-19218|-19212|-19038|-19023|-19018|-19006|-19003".
" " |-18977 |-18961| -18952|-18783|-18774|-18773|-18763|-18756|-18741|-18735|-18731|-18722|-18710|-18697".
" " " -18526|-18518 |- 18501|-18490|-18478|-18463|-18448|-18447|-18446|-18239|-18237|-18231|-18220|-18211".
" " " -18184|-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|-17482|-17468". ㅋㅋㅋ 16689|-16664". ㅋㅋㅋ 16412|-16407". ???? 16155|-15959". ???? 15659|-15652". ㅋㅋㅋ 15375|-15369". ???? 15139|-15128". ㅋㅋㅋ 14921|-14914". ㅋㅋㅋ 14654|-14645". ???? 14151|-14149". ㅋㅋㅋ 14090|-14087". ㅋㅋㅋ 13831|-13658". ???? 13343|-13340". ㅋㅋㅋ 13060|-12888". ???? 12594|-12585". + 11861|-11847". ㅋㅋㅋ 11067|-11055". + 10790|-10780". ㅋㅋㅋ 10281|-10274".
"|-10270|-10262|-10260|-10256|-10254";
$_TDataKey = 폭발('|', $_DataKey);
$_TDataValue = 폭발('|', $_DataValue);
$_Data = array_combine($_TDataKey, $_TDataValue);
arsort($_Data);
reset($_Data);
if($_Code!= 'gb2312') $_String = _U2_Utf8_Gb($_String);
$_Res = '';
for($i=0; $i
if($_P>160) {
$_Q = ord(substr($_String, ++$i, 1)); $_P = $_P*256 + $_Q - 65536;
}
$_Res .= _Pinyin($_P, $_Data);
}
return preg_replace("/[^a-z0-9]*/", '', $_Res); _ 0319 || $_Num>- 10247){
return '';
}else{
foreach($_Data as $k=>$v){ if($v<=$_Num) break; }
$k를 반환합니다.
}
}
함수 _U2_Utf8_Gb($_C){
$_String = '';
if($_C < 0x80){
$_String .= $_C;
}elseif($_C < 0x800) {
$_String .= chr(0xC0 $_C>>6);
$_String .= chr(0x80 | $_C & 0x3F);
}elseif($_C < 0x10000){
$_String .= chr(0xE0 | $_C>>12);
$_String .= chr(0x80 | $_C>>6 & 0x3F);
$_String .= chr(0x80 | $_C & 0x3F);
}elseif($_C < 0x200000) {
$_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);
}
//echo Pinyin('汉字');
//测试
echo Pinyin('中文字','gb2312'); //第二个参数“1”可随意设置即为utf8编码
위 내용은 PHP 함수--한자어를 병음으로 변환하는 함수의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!