ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ /** * gbk转拼音 * @param $txt */ function gbk_to_pinyin($txt) { if(CHARSET != 'gbk') { $txt = iconv(CHARSET,'GBK',$txt); } $l = strlen($txt); $i = 0; $pyarr = array(); $py = array(); $filename = CODETABLEDIR.'gb-pinyin.table'; $fp = fopen($filename,'r'); while(!feof($fp)) { $p = explode("-",fgets($fp,32)); $pyarr[intval($p[1])] = trim($p[0]); } fclose($fp); ksort($pyarr); while($i<$l) { $tmp = ord($txt[$i]); if($tmp>=128) { $asc = abs($tmp*256+ord($txt[$i+1])-65536); $i = $i+1; } else $asc = $tmp; $py[] = asc_to_pinyin($asc,$pyarr); $i++; } return $py; } ~~~