PHPackages                             phalapi/pinyin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. phalapi/pinyin

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phalapi/pinyin
==============

PhalApi 2.x 拼音扩展，基于overtrue/pinyin实现。

21.1k1PHP

Since Nov 22Pushed 8y ago1 watchersCompare

[ Source](https://github.com/phalapi/pinyin)[ Packagist](https://packagist.org/packages/phalapi/pinyin)[ RSS](/packages/phalapi-pinyin/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

pinyin
======

[](#pinyin)

PhalApi 2.x 拼音扩展，基于[overtrue/pinyin](https://github.com/overtrue/pinyin)实现。

安装和配置
-----

[](#安装和配置)

修改项目下的composer.json文件，并添加：

```
    "phalapi/pinyin":"dev-master"

```

然后执行`composer update`。

注册
--

[](#注册)

在/path/to/phalapi/config/di.php文件中，注册：

```
$di->pinyin = function() {
        return new \PhalApi\Pinyin\Lite();
};
```

使用
--

[](#使用)

```
\PhalApi\DI()->pinyin->convert('带着希望去旅行，比到达终点更美好');
// ["dai", "zhe", "xi", "wang", "qu", "lv", "xing", "bi", "dao", "da", "zhong", "dian", "geng", "mei", "hao"]

\PhalApi\DI()->pinyin->convert('带着希望去旅行，比到达终点更美好', PINYIN_UNICODE);
// ["dài","zhe","xī","wàng","qù","lǚ","xíng","bǐ","dào","dá","zhōng","diǎn","gèng","měi","hǎo"]

\PhalApi\DI()->pinyin->convert('带着希望去旅行，比到达终点更美好', PINYIN_ASCII);
//["dai4","zhe","xi1","wang4","qu4","lv3","xing2","bi3","dao4","da2","zhong1","dian3","geng4","mei3","hao3"]
```

选项：

选项描述`PINYIN_NONE`不带音调输出: `mei hao``PINYIN_ASCII`带数字式音调： `mei3 hao3``PINYIN_UNICODE`UNICODE 式音调：`měi hǎo`### 生成用于链接的拼音字符串

[](#生成用于链接的拼音字符串)

```
\PhalApi\DI()->pinyin->permalink('带着希望去旅行'); // dai-zhe-xi-wang-qu-lv-xing
\PhalApi\DI()->pinyin->permalink('带着希望去旅行', '.'); // dai.zhe.xi.wang.qu.lv.xing
```

### 获取首字符字符串

[](#获取首字符字符串)

```
\PhalApi\DI()->pinyin->abbr('带着希望去旅行'); // dzxwqlx
\PhalApi\DI()->pinyin->abbr('带着希望去旅行', '-'); // d-z-x-w-q-l-x
```

### 翻译整段文字为拼音

[](#翻译整段文字为拼音)

将会保留中文字符：`，。 ！ ？ ： “ ” ‘ ’` 并替换为对应的英文符号。

```
\PhalApi\DI()->pinyin->sentence('带着希望去旅行，比到达终点更美好！');
// dai zhe xi wang qu lv xing, bi dao da zhong dian geng mei hao!

\PhalApi\DI()->pinyin->sentence('带着希望去旅行，比到达终点更美好！', true);
// dài zhe xī wàng qù lǚ xíng, bǐ dào dá zhōng diǎn gèng měi hǎo!
```

### 翻译姓名

[](#翻译姓名)

姓名的姓的读音有些与普通字不一样，比如 ‘单’ 常见的音为 `dan`，而作为姓的时候读 `shan`。

```
\PhalApi\DI()->pinyin->name('单某某'); // ['shan', 'mou', 'mou']
\PhalApi\DI()->pinyin->name('单某某', PINYIN_UNICODE); // ["shàn","mǒu","mǒu"]
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/35d70b1236f8f67d96ba3da4ba88889faf2837ff8f7ab62acc54fe6cb4992c87?d=identicon)[dogstarhuang](/maintainers/dogstarhuang)

---

Top Contributors

[![dogstarTest](https://avatars.githubusercontent.com/u/6116306?v=4)](https://github.com/dogstarTest "dogstarTest (3 commits)")[![phalapi](https://avatars.githubusercontent.com/u/12585518?v=4)](https://github.com/phalapi "phalapi (1 commits)")

### Embed Badge

![Health badge](/badges/phalapi-pinyin/health.svg)

```
[![Health](https://phpackages.com/badges/phalapi-pinyin/health.svg)](https://phpackages.com/packages/phalapi-pinyin)
```

###  Alternatives

[nxp/russian-porter-stemmer

Russian porter stemmer

4490.2k1](/packages/nxp-russian-porter-stemmer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
