文件
huaqiapp/server/extend/fast/Pinyin.php
linda d14fc79e05 chore: 初始化 huaqiapp 仓库
- 前端:uni-app 基础工程(App.vue / pages / static / manifest.json 等)
- 后端:从线上服务器 huaqiapp.gzyakj.com.cn 拉取的 FastAdmin(ThinkPHP) 源码,存放于 server/
- .gitignore 排除依赖、运行时、上传目录、打包产物及含敏感信息的 AGENTS.md
2026-11-02 22:58:56 +08:00

37 行
873 B
PHP
可执行文件

<?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;
}
}