1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace Qii\Library;
- use Yurun\Util\Chinese;
- \Qii\Autoloader\Psr4::getInstance()
- ->setUseNamespaces([
- ['Yurun\Util', true],
- ])
- ->addNamespaces([
- ['Yurun\Util', Qii_DIR . DS .'Library'. DS . 'Third'. DS .'ChineseUtil'. DS . 'src'. DS],
- ]);
- /**
- * 拼音
- *
- */
- class Pinyin
- {
-
- public function __construct()
- {
-
- }
- /**
- * 获取每个字的全拼
- * @param string $str 文字
- */
- public function full($str)
- {
- return Chinese::toPinyin($str, Chinese\Pinyin::CONVERT_MODE_PINYIN)['pinyin'];
- }
- /**
- * 返回拼音、首字母、读音等
- * @param string $str
- * @return array
- */
- public function toPinyin($str) {
- return Chinese::toPinyin($str);
- }
- /**
- * 获取每个字的拼音首字母
- *
- * @param string $str 文字
- * @return mixed
- */
- public function begins($str)
- {
- return Chinese::toPinyin($str, Chinese\Pinyin::CONVERT_MODE_PINYIN_FIRST)['pinyinFirst'];
- }
- /**
- * 获取每个字的读音
- *
- * @param string $str 需要转换的内容
- * @return mixed
- */
- public function sounds($str)
- {
- return Chinese::toPinyin($str, Chinese\Pinyin::CONVERT_MODE_PINYIN_SOUND)['pinyinSound'];
- }
- /**
- * 获取每个字的读音数字
- * @param string $str 需要转换的内容
- * @return mixed
- */
- public function soundsNumber($str)
- {
- return Chinese::toPinyin($str, Chinese\Pinyin::CONVERT_MODE_PINYIN_SOUND_NUMBER)['pinyinSoundNumber'];
- }
- /**
- * 转换成简体
- *
- * @param string $str 需要转换的内容
- * @return mixed
- */
- public function toSimplified($str)
- {
- return Chinese::toSimplified($str);
- }
- /**
- * 转换成繁体
- *
- * @param string $str 需要转换的内容
- * @return mixed
- */
- public function toTraditional($str)
- {
- return Chinese::toTraditional($str);
- }
- }
|