finds.dev← search

// the find

overtrue/pinyin

★ 4,459 · PHP · MIT · updated May 2026

🇨🇳 基于词库的中文转拼音优质解决方案

A PHP library for converting Chinese characters to pinyin, backed by the mozillazg/pinyin-data dictionary. It handles the genuinely hard parts of this problem: polyphonic characters (多音字), surname pronunciation exceptions, and passport romanization rules. Useful for any PHP app that needs to generate slugs, search indexes, or sort Chinese text.

The polyphonic character handling is the main reason to use this over rolling your own — it context-disambiguates common cases like 重庆 correctly. The three-tier memory strategy (400KB vs 4MB vs adaptive) is a practical design for web vs batch workloads, not just marketing. Surname-mode is a real feature that gets edge cases right, like 单 reading as shàn in names. The CLI tool means you can wire this into non-PHP pipelines without extra glue.

Polyphonic disambiguation is dictionary-driven, not context-aware — it will still get wrong readings in ambiguous sentences that require understanding meaning. The 'smart' strategy's text-length heuristic for deciding which dictionary segments to load is a rough proxy; it won't help if your short text happens to contain rare polyphonic chars that live in a skipped segment. No streaming or incremental API, so processing a 10MB document means loading all dictionary data regardless of strategy. The word-patch contribution model (editing two text files) will produce merge conflicts under any real community usage.

View on GitHub → Homepage ↗

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →