|
@@ -0,0 +1,84 @@
|
|
|
+<?php
|
|
|
+namespace Qii\Library;
|
|
|
+
|
|
|
+\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 \Yurun\Util\Chinese::toPinyin($str, \Yurun\Util\Chinese\Pinyin::CONVERT_MODE_PINYIN)['pinyin'];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取每个字的拼音首字母
|
|
|
+ *
|
|
|
+ * @param string $str 文字
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function begins($str)
|
|
|
+ {
|
|
|
+ return \Yurun\Util\Chinese::toPinyin($str, \Yurun\Util\Chinese\Pinyin::CONVERT_MODE_PINYIN_FIRST)['pinyinFirst'];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取每个字的读音
|
|
|
+ *
|
|
|
+ * @param string $str 需要转换的内容
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function sounds($str)
|
|
|
+ {
|
|
|
+ return \Yurun\Util\Chinese::toPinyin($str, \Yurun\Util\Chinese\Pinyin::CONVERT_MODE_PINYIN_SOUND)['pinyinSound'];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取每个字的读音数字
|
|
|
+ * @param string $str 需要转换的内容
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function soundsNumber($str)
|
|
|
+ {
|
|
|
+ return \Yurun\Util\Chinese::toPinyin($str, \Yurun\Util\Chinese\Pinyin::CONVERT_MODE_PINYIN_SOUND_NUMBER)['pinyinSoundNumber'];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转换成简体
|
|
|
+ *
|
|
|
+ * @param string $str 需要转换的内容
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function toSimplified($str)
|
|
|
+ {
|
|
|
+ return \Yurun\Util\Chinese::toSimplified($str);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转换成繁体
|
|
|
+ *
|
|
|
+ * @param string $str 需要转换的内容
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function toTraditional($str)
|
|
|
+ {
|
|
|
+ return \Yurun\Util\Chinese::toTraditional($str);
|
|
|
+ }
|
|
|
+}
|