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

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

thl/pinyin
==========

Romanization tool for Traditional Chinese

1.2.5(4mo ago)2519.1k↑78.6%5MITPHPPHP &gt;=5.3.0

Since May 20Pushed 4mo ago2 watchersCompare

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

READMEChangelog (6)Dependencies (1)Versions (9)Used By (0)

PHP 華語拼音轉換工具
============

[](#php-華語拼音轉換工具)

將字串中之漢字視為華語，並轉換成各種拼音形式之工具

### 支援拼音法

[](#支援拼音法)

- 注音拼音 (Bopomofo)
- 臺灣華語羅馬拼音 (THL)
- 漢語拼音
- 通用拼音
- 注音二式
- 威妥瑪拼音

### 安裝方式

[](#安裝方式)

建議使用 php-composer 安裝

```
composer require thl/pinyin
```

### 使用說明

[](#使用說明)

#### Pinyin::bpmf()

[](#pinyinbpmf)

將字串內漢字以華語注音符號表示

```
string THL\Pinyin::bpmf(string $source)
```

##### 參數

[](#參數)

- $source 輸入字串

##### 範例

[](#範例)

```
// returns "THL ㄊㄞˊ ㄨㄢ ㄏㄨㄚˊ ㄩˇ ㄌㄨㄛˊ ㄇㄚˇ ㄆㄧㄣ ㄧㄣ"
$output = THL\Pinyin::bpmf("THL台灣華語羅馬拼音");
```

#### Pinyin::pinyin()

[](#pinyinpinyin)

將字串內漢字以華語拼音表示

```
string THL\Pinyin::pinyin(string $source, array $options)
```

##### 參數

[](#參數-1)

- $source 輸入字串
- $options 參數
    - notation: 方案，預設為 thl
        - thl (台灣華語羅馬拼音)
        - hy (漢語拼音)
        - ty (通用拼音)
        - mps2 (注音二式)
        - wg (威妥瑪拼音)
    - tone: 聲調，預設為 number
        - number (數字表示)
        - mark (符號表示) 目前暫時只支援臺灣華語羅馬拼音 (THL)
        - none (無聲調)
    - split: 分割，預設為 word
        - word (單字)
        - phrase (詞)

##### 範例

[](#範例-1)

```
// returns "THL tai2 wan1 hua2 yu3 luo2 ma3 pin1 yin1"
$output = THL\Pinyin::pinyin("THL台灣華語羅馬拼音");

// returns "THL taíwan huáyǔ luómǎ pinyin"
$output = THL\Pinyin::pinyin("THL台灣華語羅馬拼音", array('tone' => 'mark', 'split' => 'phrase'));

// returns "THL t'ai wan hua yü lo ma p'in yin"
$output = THL\Pinyin::pinyin("THL台灣華語羅馬拼音", array('notation' => 'wg', 'tone' => 'none', 'split' => 'word'));
```

#### Pinyin::slug()

[](#pinyinslug)

產生適合當網址的格式

```
string THL\Pinyin::slug(string $source, array $options)
```

##### 參數

[](#參數-2)

- $source 輸入字串
- $options 參數
    - notation: 方案，預設為 thl
        - thl (台灣華語羅馬拼音)
        - hy (漢語拼音)
        - ty (通用拼音)
        - mps2 (注音二式)
        - wg (威妥瑪拼音)
    - tone: 聲調，預設為 none
        - number (數字表示)
        - none (無聲調)
    - split: 分割，預設為 word
        - word (單字)
        - phrase (詞)

##### 範例

[](#範例-2)

```
// returns "thl-tai-wan-hua-yu-luo-ma-pin-yin"
$output = THL\Pinyin::pinyin("THL台灣華語羅馬拼音");

// returns "thl-taiwan-huayu-luoma-pinyin"
$output = THL\Pinyin::pinyin("THL台灣華語羅馬拼音", array('split' => 'phrase'));

// returns "thl-tai2wan1-hua2yu3-luo2ma3-pin1yin1"
$output = THL\Pinyin::pinyin("THL台灣華語羅馬拼音", array('notation' => 'ty', 'tone' => 'number', 'split' => 'phrase'));
```

### 詞庫

[](#詞庫)

詞庫的部份以[小麥注音](https://mcbopomofo.openvanilla.org)為基礎，字的部份另外使用[cconv](https://github.com/xiaoyjy/cconv) 翻譯成簡體漢字

- 由於詞庫部份尚未翻譯為中式華語，以簡體漢字書寫之句子有大部份的情況會被視為獨立單字組成

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance74

Regular maintenance activity

Popularity37

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 83.3% 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 ~553 days

Recently: every ~631 days

Total

8

Last Release

145d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/09b7d171dc5bc1af37aa6c01159e96291a4c073f2e6b439af77fe5b24f4fd099?d=identicon)[thlgrant](/maintainers/thlgrant)

![](https://www.gravatar.com/avatar/1e20210af3bff389947ebe48495a2171155899f2948369fce6589721719fcf4e?d=identicon)[thl](/maintainers/thl)

---

Top Contributors

[![whsyu](https://avatars.githubusercontent.com/u/2595221?v=4)](https://github.com/whsyu "whsyu (15 commits)")[![jfcherng](https://avatars.githubusercontent.com/u/6594915?v=4)](https://github.com/jfcherng "jfcherng (2 commits)")[![asika32764](https://avatars.githubusercontent.com/u/1639206?v=4)](https://github.com/asika32764 "asika32764 (1 commits)")

---

Tags

PinyinChinesebopomofo

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[overtrue/pinyin

Chinese to pinyin translator.

4.5k6.5M72](/packages/overtrue-pinyin)[zhuzhichao/ip-location-zh

get the ip's location info with Chinese

617212.5k11](/packages/zhuzhichao-ip-location-zh)[overtrue/chinese-calendar

中国农历转换与查询工具

557103.7k4](/packages/overtrue-chinese-calendar)[zhuzhichao/bank-card-info

Get the bank card info

45464.8k](/packages/zhuzhichao-bank-card-info)[douyasi/identity-card

Chinese Identity Card package

17851.4k3](/packages/douyasi-identity-card)[wilon/php-number2chinese

PHP数字转为汉字描述、人民币大写方法。

14632.0k1](/packages/wilon-php-number2chinese)

PHPackages © 2026

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