GithubHelp home page GithubHelp logo

dictpedia / zhuyinpinyin Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 3.0 15 KB

A PHP library that deals with Zhuyin (注音) to Pinyin (漢語拼音), Pinyin to Zhuyin.

Home Page: https://zh.dictpedia.org

PHP 100.00%
zhuyin pinyin chinese-characters php-library

zhuyinpinyin's Introduction

ZhuyinPinyin

A PHP library that deals with Zhuyin (注音) to 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.

這個函式庫的原始邏輯設計出自以 Golang 編寫,因為本人需要用在字典百科專案中,但尋無以 PHP 版本實現的注音轉拼音、拼音轉注音的函式庫,所以我把它從 Golang 改寫成 PHP 版本。

  • 此PHP 版與 Golang 原版的差別是捨棄字串陣列,分別讀取個別字元進去陣列以避免可能的 UTF-8字元問題
  • 原始邏輯已經處理的很好了,所以直接移植為 PHP 版本。只加了一個函式 splitString 來處理個別 UTF-8 字元

Install

composer require dictpedia/zhuyin-pinyin

Usage

$zh = new \DictPedia\ZhuyinPinyin();

Resutn empty string if the input string is invaild.

API

encodePinyin

echo $zh->encodePinyin('zhang1');

// result: zhāng

decodePinyin

echo $zh->decodePinyin('zhāng');

// result: zhang1

encodeZhuyin

echo $zh->encodeZhuyin('zhang1');

// result: ㄓㄤ

decodeZhuyin

echo $zh->decodeZhuyin('ㄓㄤ');

// result: zhang1

pinyinToZhuyin

echo $zh->pinyinToZhuyin('zhāng');

// result: ㄓㄤ

zhuyinToPinyin

echo $zh->zhuyinToPinyin('ㄓㄤ');

// result: zhāng

License

MIT

https://packagist.org/packages/dictpedia/zhuyin-pinyin

zhuyinpinyin's People

Contributors

terrylinooo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

zhuyinpinyin's Issues

misspelling of array

there is a misspelling of the array
"zhuyin_tones" it is declared as:
$zhyuin_tones and later referenced with the same so tone numbers dont show up.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.