/*--------------------------* Kanji to Pinyin * $str the string to convert * $split if you want to split the display * $isfirst return the first letter
* _cnfonts.php (a total of 25961 characters, including 20902 basic words + 5059 uncommon words)
* Http://files.cnblogs.com/files/helin/_cnfonts.zip-*------------------------*/ functionPinYin ($str,$split=true,$isfirst=false){ Static $pinyins; if(!isset($pinyins)){ include_once' _cnfonts.php ';//$_cnfonts= ' ... '; $a 1=Explode(' | ',$_cnfonts); $pinyins=Array(); foreach($a 1 as $v) { $a 2=Explode(‘:‘,$v); $pinyins[$a 2[0]] =$a 2[1]; } } $py= ' '; $str=Trim($str); $str _arr=Preg_split('/(? <!^) (?! $)/U ',$str ); foreach($str _arr as $code){ if(isset($pinyins[$code])) { $py.= ($split&&$py? ‘ ‘ : ‘‘ ). ($isfirst?Strtoupper($pinyins[$code][0]):$pinyins[$code]); }Else{ $py.=$code; } } return $py; }
Kanji to Pinyin