Based on the Cc-cedict Dictionary of Chinese Pinyin tool, more accurate Chinese pinyin solution.
SAE Service Address: http://string2pinyin.sinaapp.com/doc.html
Use \overtrue\pinyin\pinyin;echo Pinyin::trans (' Travelling with hope, better than reaching the finish line ');//Dài Zhe xīwàng qùlǔxíng bǐdào dázhōng diǎn gèng Měi hǎo//Polyphone//Pinyin::trans (' clear '); Liǎo Ránpinyin::trans (' Come '); Lái le//also Pinyin::trans (' also '); Hái Yǒupinyin::trans (' surrender '); Jiāo huán//Pinyin::trans (' What '); Shén Mepinyin::trans (' assorted '); shíjǐn//will Pinyin::trans (' Bento '); Biàn dāngpinyin::trans (' cheap '); Pián yí//stripping Pinyin::trans (' peeling '); Bāo Pípinyin::trans (' peeling device '); bōpíqì//not Pinyin::trans (' Make an apology '); Péi Búshipinyin::trans (' Run the monk, can't run the Temple '); Pǎo le héshàng, pǎo bùliǎo miào//descending pinyin::trans (' cooling '); Jiàng Wēnpinyin::trans (' surrender '); Tóu xiáng//Pinyin::trans (' capital '); Shǒu Dūpinyin::trans (' all ages '); Dōu shén me nián dài le//le Pinyin::trans (' happy '); Kuài Lèpinyin::trans (' Music '); Yīn yuè//long Pinyin::trans (' growth '); Chéng Zhǎngpinyin::trans (' Changjiang '); Cháng jiāng//Difficult Pinyin::trans (' refugees '); Nàn Mínpinyin::trans (' sad '); Nán Guò
Installation
To install using Composer:
Composer require overtrue/pinyin:2.*
or join in your project Composer.json:
{"Require": {"Overtrue/pinyin": "2.*"}}
The direct download file src/pinyin/pinyin.php introduced into the project.
Use
' Travel with hope, better than finish ',// ' pinyin ' = ' Dài zhe xīwàng qùlǔxíng bǐdào dázhōng diǎn gèng měi hǎo ',/' Letter ' =& Gt ' d z x w q L x b d d z d g M h ',//);//Load custom supplemental Thesaurus $appends = Array ( ' cold ' = ' Re4 ',); Pinyin::appends ($appends); Echo Pinyin::trans (' cold ');//Rè
Set up
Options |
Description |
Delimiter |
Delimiter, default is a space |
Accent |
Whether to output tones |
Only_chinese |
Keep only the Chinese part of $string |
Uppercase |
Uppercase when first letter is taken, default false |
Global Settings: Pinyin::set (' delimiter ', '-');
Temporary settings: Pinyin::trans ($word, $settings) after calling the method to pass the parameter
Example
Pinyin::set (' delimiter ', '-');//Global echo Pinyin::trans (' Travelling with hope, better than reaching the finish line ');// dài-zhe-xī-wàng-qù-lǔ-xíng-bǐ-dào-dá-zhōng-diǎn-gèng-měi-hǎo$setting = [ ' delimiter ' = '-', ' accent ' = = False, ]; echo Pinyin::trans (' Travel with hope, better than to finish ', $setting);//The setting here is just a temporary modification, not a global setting/ Dai-zhe-xi-wang-qu-lu-xing-bi-dao-da-zhong-dian-geng-mei-hao
Pinyin::set (' accent ', false); Echo Pinyin::trans (' Travelling with hope, better than reaching the end '); Dai Zhe Xi Wang qu Lu xing bi dao da zhong dian Geng Mei Hao
Use in Laravel
The separate package is here: Overtrue/laravel-pinyin
Use
As with the above method:
Use \overtrue\pinyin\pinyin;//... $pinyin = Pinyin::trans ("To travel with hope, better than to reach the end");
ODO
- Add get first letter;
- Add supplemental dictionaries;
- Add an audio table to improve the polyphone accuracy of unmatched dictionaries based on audio;
- Add the first letter output case option uppercase;
- Support for loading custom thesaurus: pinyin::appends ($appends = Array ());
- Support for Laravel 5 service provider. Overtrue/laravel-pinyin
Https://github.com/overtrue/pinyin