代码初始化
This commit is contained in:
36
extend/fast/Pinyin.php
Normal file
36
extend/fast/Pinyin.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace fast;
|
||||
|
||||
/**
|
||||
* 中文转拼音类
|
||||
*/
|
||||
class Pinyin
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取文字的拼音
|
||||
* @param string $chinese 中文汉字
|
||||
* @param boolean $onlyfirst 是否只返回拼音首字母
|
||||
* @param string $delimiter 分隔符
|
||||
* @param bool $ucfirst 是否首字母大写
|
||||
* @return string
|
||||
*/
|
||||
public static function get($chinese, $onlyfirst = false, $delimiter = '', $ucfirst = false)
|
||||
{
|
||||
|
||||
$pinyin = new \Overtrue\Pinyin\Pinyin();
|
||||
if ($onlyfirst) {
|
||||
$result = $pinyin->abbr($chinese, $delimiter);
|
||||
} else {
|
||||
$result = $pinyin->permalink($chinese, $delimiter);
|
||||
}
|
||||
if ($ucfirst) {
|
||||
$pinyinArr = explode($delimiter, $result);
|
||||
$result = implode($delimiter, array_map('ucfirst', $pinyinArr));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user