PHPackages                             mucts/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. mucts/pinyin

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

mucts/pinyin
============

Chinese to pinyin translator.

1.0.5(5y ago)515941MITPHPPHP &gt;=7.4

Since May 21Pushed 5y agoCompare

[ Source](https://github.com/mucts/pinyin)[ Packagist](https://packagist.org/packages/mucts/pinyin)[ RSS](/packages/mucts-pinyin/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (7)Used By (1)

[![](https://camo.githubusercontent.com/e27473a2cc76c25e71f47614427ff9e36425423a903be0290741a035ed26d42b/68747470733a2f2f696d616765732e6d756374732e636f6d2f696d6167652f6578705f6465665f77686974652e706e67)](https://camo.githubusercontent.com/e27473a2cc76c25e71f47614427ff9e36425423a903be0290741a035ed26d42b/68747470733a2f2f696d616765732e6d756374732e636f6d2f696d6167652f6578705f6465665f77686974652e706e67)

 [![Build Status](https://camo.githubusercontent.com/943d12855227c3a23e880e13602011ca7e75eba42e1f3419320cd9f59017445f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d756374732f70696e79696e2f6261646765732f6275696c642e706e67)](https://scrutinizer-ci.com/g/mucts/pinyin) [![Code Intelligence Status](https://camo.githubusercontent.com/15c2f9838826d28478ccc4ee6f80771fa240c005372ddf2bf092217a2e80889f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d756374732f70696e79696e2f6261646765732f636f64652d696e74656c6c6967656e63652e737667)](https://scrutinizer-ci.com/g/mucts/pinyin) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/e0ef4870c6fce4d56da118d8ddca62dde261bc386b2d40ff77525a5c95d1fae2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d756374732f70696e79696e2f6261646765732f7175616c6974792d73636f72652e706e67)](https://scrutinizer-ci.com/g/mucts/pinyin) [![Total Downloads](https://camo.githubusercontent.com/bf58e8d06742779fb4c8720fe00a1e9c2c32639784cfe518474e6a11e84ea314/68747470733a2f2f706f7365722e707567782e6f72672f6d756374732f70696e79696e2f642f746f74616c2e737667)](https://packagist.org/packages/mucts/pinyin) [![Latest Stable Version](https://camo.githubusercontent.com/a5daa3887abe54aa83a1f6fe88b2fc26fd61ba362e84b6d4a45cdb01cae24a07/68747470733a2f2f706f7365722e707567782e6f72672f6d756374732f70696e79696e2f762f737461626c652e737667)](https://packagist.org/packages/mucts/pinyin) [![License](https://camo.githubusercontent.com/75e95a0f85341c950632ffeda31073f3f58a57bdfe13c72bbc6386408b42d231/68747470733a2f2f706f7365722e707567782e6f72672f6d756374732f70696e79696e2f6c6963656e73652e737667)](https://packagist.org/packages/mucts/pinyin)

Pinyin
======

[](#pinyin)

> 基于 [CC-CEDICT](http://cc-cedict.org/wiki/) 词典的中文转拼音工具，更准确的支持多音字的汉字转拼音解决方案。

安装
--

[](#安装)

使用 Composer 安装:

```
$ composer require mucts/pinyin

```

使用
--

[](#使用)

可选转换方案：

- 内存型，适用于服务器内存空间较富余，优点：转换快
- 小内存型(默认)，适用于内存比较紧张的环境，优点：占用内存小，转换不如内存型快
- I/O型，适用于虚拟机，内存限制比较严格环境。优点：非常微小内存消耗。缺点：转换慢，不如内存型转换快,php &gt;= 5.5

可用选项：
-----

[](#可用选项)

选项描述`TONE`UNICODE 式音调：`měi hǎo``ASCII_TONE`带数字式音调： `mei3 hao3``NO_TONE`无音调：`mei hao``KEEP_NUMBER`保留数字`KEEP_ENGLISH`保留英文`KEEP_PUNCTUATION`保留标点`UMLAUT_V`使用 `v` 代替 `yu`, 例如：吕 `lyu` 将会转为 `lv`### 拼音数组

[](#拼音数组)

```
use MuCTS\Pinyin\Pinyin;
use MuCTS\Pinyin\Loaders\MemoryFile;
use MuCTS\Pinyin\Loaders\GeneratorFile;

// 小内存型
$pinyin = new Pinyin(); // 默认
// 内存型
// $pinyin = new Pinyin(MemoryFile::class);
// I/O型
// $pinyin = new Pinyin(GeneratorFile::class);

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

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

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

- 小内存型: 将字典分片载入内存
- 内存型: 将所有字典预先载入内存
- I/O型: 不载入内存，将字典使用文件流打开逐行遍历并运用php5.5生成器(yield)特性分配单行内存

### 生成用于链接的拼音字符串

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

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

### 获取首字符字符串

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

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

$pinyin->abbr('你好2018！', Pinyin::KEEP_NUMBER); // nh2018
$pinyin->abbr('Happy New Year! 2018！', Pinyin::KEEP_ENGLISH); // HNY2018
```

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

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

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

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

$pinyin->sentence('带着希望去旅行，比到达终点更美好！', Pinyin::TONE);
// 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`。

```
$pinyin->name('单某某');
// ['shan', 'mou', 'mou']
$pinyin->name('单某某', Pinyin::TONE);
// ["shàn","mǒu","mǒu"]
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~1 days

Total

6

Last Release

2177d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/102022?v=4)[Herry Leonard](/maintainers/herry)[@herry](https://github.com/herry)

---

Top Contributors

[![yuandeng](https://avatars.githubusercontent.com/u/69410645?v=4)](https://github.com/yuandeng "yuandeng (18 commits)")

---

Tags

cc-cedictpinyinpinyin-datapinyin-php

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[phpmath/biginteger

A PHP library to work with big integers.

235.8k1](/packages/phpmath-biginteger)

PHPackages © 2026

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