PHP Chinese tools ChineseUtil, support Pinyin, phonetic word, Simplified and Traditional conversion, digital, the amount of capital;
This dictionary data library contains a total of 73,925 characters, comprising: 3955 simplified and traditional Chinese characters 1761, 68,209 other characters.
Cloud code: https://gitee.com/yurunsoft/ChineseUtil
Github:https://github.com/Yurunsoft/ChineseUtil
v1.1.2 Updates
* Fixed a series of problems caused by the conversion difference PHP version, environment, pattern, resulting in the
* Test blessing, to ensure stability library
Instructions for use
Composer installed directly
composer require yurunsoft/chinese-util
Composer project configuration introduced
"require": {
"yurunsoft/chinese-util" : "~1.0"
}
Features
Pinyin
use \ Yurun \ Util \ Chinese; use \ Yurun \ Util \ Chinese \ Pinyin; $ String = 'good fortune! 123 '; echo $ String, value is PHP_EOL; echo' spelling: ', value is PHP_EOL; var_dump (Chinese :: toPinyin ($ String, Pinyin :: CONVERT_MODE_PINYIN)); echo' initials: ', value is PHP_EOL; var_dump (Chinese :: toPinyin ($ String, Pinyin :: CONVERT_MODE_PINYIN_FIRST)); echo 'pronunciation:', value is PHP_EOL; var_dump (Chinese :: toPinyin ($ String, Pinyin :: CONVERT_MODE_PINYIN_SOUND)); echo 'pronunciation numbers:', value is PHP_EOL; var_dump (Chinese :: toPinyin ($ String, Pinyin :: CONVERT_MODE_PINYIN_SOUND_NUMBER)); echo 'managed return text format returns + + custom delimiter:', value is PHP_EOL; var_dump (Chinese :: toPinyin ($ String, Pinyin :: CONVERT_MODE_PINYIN | :: Pinyin CONVERT_MODE_PINYIN_SOUND_NUMBER, '')); var_dump (Chinese :: toPinyin ($ String)); echo 'undivided without Pinyin character:', PHP_EOL; var_dump (Chinese :: toPinyin ($ String, Pinyin :: CONVERT_MODE_PINYIN, '', false)); // results too long, run the code to see your own
Pinyin word
use \ Yurun \ Util \ Chinese; $ string2 = 'Xianggang'; echo ' "', $ string2, '" the segmentation results:', value is PHP_EOL; var_dump (Chinese :: splitPinyin ($ string2)); / ** output : "Xianggang" of word segmentation results: Array (2) { [0] => String (12 is) "Ang XI Gang" [. 1] => String (. 11) "Xiang Gang" } * /
Simplified and Traditional Huzhuan
use \ Yurun \ Util \ Chinese; $ string3 = 'People's Republic of China! Kung Hei Fat Choi! '; Echo' " ', $ string3,'" Simplified conversion: ', PHP_EOL; var_dump (Chinese :: toSimplified ($ string3)); echo' " ', $ string3,'" Traditional conversion: ', PHP_EOL; var_dump (Chinese :: toTraditional ($ string3)); / ** output: "!! Congratulations rich People's Republic of China" Simplified conversion: Array (. 1) { [0] => String (39) "People's Republic of China! Congratulations! fortune " } !!" good fortune People's Republic of China "Traditional conversion: Array (. 1) { [0] => String (39)"!! Congratulations rich People's Republic of China " } * /
Digital conversion
Yurun use \ Util \ Chinese \ Number The; function Test ($ Number) { $ chinese :: = Number The toChinese ($ Number, [ 'tenMin' => to true, // "twelve" => "twelve" ]) ; $ afterNumber if toNumber :: = Number The ($ chinese); echo Number $, '=>', chinese $, '=>', $ afterNumber, '=>', 0 === bccomp (Number $, $ afterNumber, ? 20 is) 'to true': 'to false', value is PHP_EOL; } Test (1.234); Test (-1234567890.666); Test (PI ()); / ** output: 1.234 => one two Sansi => = 1.234 > to true -1234567890.666 => negative Shier Yi 34567890.666 => - 1,234,567,890.666 => to true 3.1415926535898 => Sandian 1415926535 eight hundred ninety-eight => 3.1415926535898 => to true * /
Amount digital conversion
Yurun use \ Util \ Chinese \ Money; function Test ($ Number) { $ Money :: = chinese toChinese ($ Number, [ 'tenMin' => to true, // "twelve" => "twelve" ]) ; $ afterMoney Money :: = if toNumber ($ chinese); echo Number $, '=>', chinese $, '=>', $ afterMoney, '=>', 0 === bccomp (Number $, $ afterMoney) ? 'to true': 'to false', value is PHP_EOL; } Test (1.234); Test (-1234567890.666); / ** output: 1.234 => One-third round angle II store centipoise => = 1.234> to true -1234567890.666 => negative II one hundred million one hundred three thousand Sibai Lu Wan Qi Qian Wu Shi Ba Lu Bai Jiu Shi round the corner points Lu Lu PCT => - 1234567890.666 => to true * /