A PHP library that deals with Zhuyin (phonetic notation) to Pinyin (汉语Pinyin), Pinyin to Zhuyin.
https://github.com/localvar/zhuyin (Golang version)
The original idea is from a Golang library written by Bomin Zhang , I recoding it with PHP and using on DictPedia project.
For example, this library will translate zhang1 to zhāng (pinyin) or ㄓㄤ (zhuyin), zhāng or ㄓㄤ decode to zhang1 , and also support pinyin to zhuyin and zhuyin to pinyin .
The original logic design of this function library was written in Golang because I needed to use it in a dictionary encyclopedia project, but I could not find a PHP version of the function library that converts Zhuyin to Pinyin and Pinyin to Zhuyin, so I rewrote it from Golang. into PHP version.
composer require dictpedia/zhuyin-pinyin
$ zh = new DictPedia ZhuyinPinyin ();
Resutn empty string if the input string is invalid.
echo $ zh -> encodePinyin ( ' zhang1 ' );
// result: zhāng
echo $ zh -> decodePinyin ( ' zhāng ' );
// result: zhang1
echo $ zh -> encodeZhuyin ( ' zhang1 ' );
// result: ㄓㄤ
echo $ zh -> decodeZhuyin ( ' ㄓㄤ ' );
// result: zhang1
echo $ zh -> pinyinToZhuyin ( ' zhāng ' );
// result: ㄓㄤ
echo $ zh -> zhuyinToPinyin ( ' ㄓㄤ ' );
// result: zhāng
MIT
https://packagist.org/packages/dictpedia/zhuyin-pinyin