Git Product home page Git Product logo

pinyin-1's Introduction

Pinyin

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

🇨🇳 基于 CC-CEDICT 词典的中文转拼音工具,更准确的支持多音字的汉字转拼音解决方案。

Sponsor me

安装

使用 Composer 安装:

composer require overtrue/pinyin

使用

选项

选项 描述
PINYIN_TONE UNICODE 式音调:měi hǎo
PINYIN_ASCII_TONE 带数字式音调: mei3 hao3
PINYIN_NO_TONE 无音调:mei hao
PINYIN_KEEP_NUMBER 保留数字
PINYIN_KEEP_ENGLISH 保留英文
PINYIN_KEEP_PUNCTUATION 保留标点
PINYIN_UMLAUT_V 使用 v 代替 yu, 例如:吕 lyu 将会转为 lv

拼音数组

use Overtrue\Pinyin\Pinyin;

$pinyin = new Pinyin(); // 默认

$pinyin->convert('带着希望去旅行,比到达终点更美好');
// ["dai", "zhe", "xi", "wang", "qu", "lyu", "xing", "bi", "dao", "da", "zhong", "dian", "geng", "mei", "hao"]

$pinyin->convert('带着希望去旅行,比到达终点更美好', PINYIN_TONE);
// ["dài","zhe","xī","wàng","qù","lǚ","xíng","bǐ","dào","dá","zhōng","diǎn","gèng","měi","hǎo"]

$pinyin->convert('带着希望去旅行,比到达终点更美好', PINYIN_ASCII_TONE);
//["dai4","zhe","xi1","wang4","qu4","lyu3","xing2","bi3","dao4","da2","zhong1","dian3","geng4","mei3","hao3"]

生成用于链接的拼音字符串

$pinyin->permalink('带着希望去旅行'); // dai-zhe-xi-wang-qu-lyu-xing
$pinyin->permalink('带着希望去旅行', '.'); // dai.zhe.xi.wang.qu.lyu.xing

获取首字符字符串

$pinyin->abbr('带着希望去旅行'); // dzxwqlx
$pinyin->abbr('带着希望去旅行', '-'); // d-z-x-w-q-l-x

$pinyin->abbr('你好2018!', PINYIN_KEEP_NUMBER); // nh2018
$pinyin->abbr('Happy New Year! 2018!', PINYIN_KEEP_ENGLISH); // HNY2018

翻译整段文字为拼音

将会保留中文字符:,。 ! ? : “ ” ‘ ’ 并替换为对应的英文符号。

$pinyin->sentence('带着希望去旅行,比到达终点更美好!');
// dai zhe xi wang qu lyu xing, bi dao da zhong dian geng mei hao!

$pinyin->sentence('带着希望去旅行,比到达终点更美好!', PINYIN_TONE);
// dài zhe xī wàng qù lǚ xíng, bǐ dào dá zhōng diǎn gèng měi hǎo!

翻译姓名

姓名的姓的读音有些与普通字不一样,比如 ‘单’ 常见的音为 dan,而作为姓的时候读 shan

$pinyin->name('单某某'); // ['shan', 'mou', 'mou']
$pinyin->name('单某某', PINYIN_TONE); // ["shàn","mǒu","mǒu"]

更多使用请参考 测试用例

在 Laravel 中使用

独立的包在这里:overtrue/laravel-pinyin

Contribution

欢迎提意见及完善补充词库:

参考

❤️ Sponsor me

Sponsor me

如果你喜欢我的项目并想支持它,点击这里 ❤️

Project supported by JetBrains

Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.

PHP 扩展包开发

想知道如何从零开始构建 PHP 扩展包?

请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》

License

MIT

pinyin-1's People

Contributors

overtrue avatar xjchengo avatar medz avatar rookie20570 avatar dependabot-preview[bot] avatar dependabot[bot] avatar aizuyan avatar liuxd avatar ssynhtn avatar allowing avatar luokuncool avatar wiseker avatar fossabot avatar drl3fty avatar shengbinxu avatar abrahamgreyson avatar wangfenjin avatar summerblue avatar aufree avatar n0ah avatar modilay avatar totoleo avatar kmvan avatar domainname avatar honvid avatar garveen avatar wfyhehe avatar

Stargazers

 avatar

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.