From bfc47ec9b252c523f323869282b31a0deb07538c Mon Sep 17 00:00:00 2001 From: gongfuxiang Date: Sun, 9 Oct 2022 23:52:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B1=89=E5=AD=97=E8=BD=AC=E6=8B=BC=E9=9F=B3?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/common.php b/app/common.php index a42d5caa7..0a0983ed5 100755 --- a/app/common.php +++ b/app/common.php @@ -11,6 +11,23 @@ // 应用公共文件 +/** + * 获取汉字拼音、默认返回数组 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2022-10-09 + * @desc description + * @param [string] $string [汉字] + * @param [boolean] $is_string [返回字符串] + * @param [string] $join [字符串连接符号] + */ +function ChinesePinyin($string, $is_string = false, $join = '') +{ + $value = (new \Overtrue\Pinyin\Pinyin())->convert($string); + return ($is_string && is_array($value)) ? implode($join, $value) : $value; +} + /** * 获取汉字首字母 * @author Devil @@ -20,10 +37,10 @@ * @desc description * @param [string] $string [汉字] */ -function PinyinLetter($string) +function ChineseLetter($string) { - $letter = (new \Overtrue\Pinyin\Pinyin())->abbr($string); - return empty($letter) ? '' : $letter; + $value = (new \Overtrue\Pinyin\Pinyin())->abbr($string); + return empty($value) ? '' : $value; } /**