Full Download:
Http://dwz.cn/6NnaP0
The core code is as follows:
<?php/**** Kanji **/class chinesepinyin{//utf-8 Chinese character set private $ChineseCharacters;//code private $charset = ' utf-8 '; Public Function __construct () {if (Empty ($this->chinesecharacters)) {$this->chinesecharacters = file_get_ Contents (' ChineseCharacters.dat ');}} /** converted to phonetic pinyin * param $input _char string needs to be converted Kanji * param $delimiter string conversion between pinyin delimiter * param $outside _ignore Boolean Whether to ignore non-Chinese content */public function Transformwithtone ($input _char, $delimiter = ", $outside _ignore=false) {$input _len = mb_ Strlen ($input _char, $this->charset), $output _char = ", for ($i =0; $i < $input _len; $i + +) {$word = Mb_substr ($input _ Char, $i, 1, $this->charset), if (Preg_match ('/^[\x{4e00}-\x{9fa5}]$/u ', $word) && preg_match ('/\, '. Preg_ QUOTE ($word). ' (.*?) \,/', $this->chinesecharacters, $matches) {$output _char.= $matches [1]. $delimiter;} else if (! $outside _ignore) {$output _char.= $word;}} return $output _char;} /** turn into a non-tonal Hanyu Pinyin * param $input _char string needs to be converted Kanji * param $delimiter string converted after the pinyin delimiter between * param $outside_ignore Boolean ignores non-kanji content */public function transformwithouttone ($input _char, $delimiter = ", $outside _ignore=true) {$ Char_with_tone = $this->transformwithtone ($input _char, $delimiter, $outside _ignore); $char _without_tone = Str_ Replace (Array (' ā ', ' á ', ' ǎ ', ' à ', ' ō ', ' Ó ', ' ǒ ', ' Ò ', ' ッ ', ' é ', ' canít ', ' è ', ' ī ', ' í ', ' ǐ ', ' ì ', ' ū ', ' ú ', ' ǔ ', ' Ù ', ' disables ', ' Ǘ ', ' clean ', ' Ǜ ', ' U '), array (' A ', ' a ', ' a ', ' a ', ' o ', ' o ', ' o ', ' o ', ' e ', ' e ', ' e ', ' e ', ' I ', ' I ', ' I ', ' I ', ' u ', ' u ', ' u ', ' u ', ' V ', ' V ', ' V ', ' V ', ' V ' ), $char _with_tone); return $char _without_tone;} /** converted to Hanyu Pinyin * param $input _char string needs to be converted Kanji * param $delimiter string converted between pinyin delimiter */public function transformucwords ($input _char, $delimiter = ") {$char _without_tone = ucwords ($this->transformwithouttone ($input _char, "true)); $ucwords = Preg_replace ('/[^a-z ]/', ', $char _without_tone), if (!empty ($delimiter)) {$ucwords = implode ($delimiter, Str_split ($ucwords));} return $ucwords;}}? >
Examples of Use:
<?phpinclude ' ChinesePinyin.class.php '; $Pinyin = new Chinesepinyin (); $words = ' kanji into pinyin class '; Echo '
;
PHP Kanji to Pinyin