فهرست منبع

Add: 拼音工具

Zhu Jinhui 6 سال پیش
والد
کامیت
6bca5c5684
2فایلهای تغییر یافته به همراه85 افزوده شده و 0 حذف شده
  1. 84 0
      src/Library/Pinyin.php
  2. 1 0
      src/Library/Third/ChineseUtil

+ 84 - 0
src/Library/Pinyin.php

@@ -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);
+    }
+}

+ 1 - 0
src/Library/Third/ChineseUtil

@@ -0,0 +1 @@
+Subproject commit 81ec4e42ff3182f8bba8fac596138b63c84c1a9c