overtrue/laravel-pinyin
Composer 安装命令:
composer require overtrue/laravel-pinyin
包简介
Chinese to Pinyin translator.
README 文档
README
Chinese to Pinyin translator for Laravel based on overtrue/pinyin.
Install
composer require "overtrue/laravel-pinyin:^6.0"
The auto-discovery feature will handle these two steps for you.
Add the following line to the section providers of config/app.php:
'providers' => [ //... Overtrue\LaravelPinyin\ServiceProvider::class, ],
as optional, you can use facade:
'aliases' => [ //... 'Pinyin' => Overtrue\LaravelPinyin\Facades\Pinyin::class, ],
Usage
you can get the instance of Overtrue\Pinyin\Pinyin from app container:
$pinyin = app('pinyin'); echo $pinyin->sentence('带着希望去旅行,比到达终点更美好'); // dài zhe xī wàng qù lǔ xíng, bǐ dào dá zhōng diǎn gèng měi hǎo
There are more convenient functions:
| function | method |
|---|---|
pinyin() |
app('pinyin')->convert() |
pinyin_abbr() |
app('pinyin')->abbr() |
pinyin_permalink |
app('pinyin')->permalink() |
pinyin_sentence |
app('pinyin')->sentence() |
var_dump(pinyin('带着希望去旅行,比到达终点更美好')); // ["dai", "zhe", "xi", "wang", "qu", "lv", "xing", "bi", "dao", "da", "zhong", "dian", "geng", "mei", "hao"] var_dump(pinyin_abbr('带着希望去旅行')); // dzxwqlx ...
Using facade:
use Pinyin; // Facade class, NOT Overtrue\Pinyin\Pinyin var_dump(Pinyin::convert('带着希望去旅行')); // ["dai", "zhe", "xi", "wang", "qu", "lv", "xing"] echo Pinyin::sentence('带着希望去旅行,比到达终点更美好'); // dài zhe xī wàng qù lǔ xíng, bǐ dào dá zhōng diǎn gèng měi hǎo
About overtrue/pinyin specific configuration and use, refer to: overtrue/pinyin
Performance Strategies (New in 6.0)
Laravel-pinyin 6.0 includes support for the new performance optimization strategies introduced in overtrue/pinyin 6.0:
use Overtrue\Pinyin\Pinyin; // Memory Optimized (default) - ~400KB memory usage, suitable for web requests Pinyin::useMemoryOptimized(); // Cached Strategy - ~4MB memory usage, 2-3x faster for repeated conversions Pinyin::useCached(); // Smart Strategy - 600KB-1.5MB memory usage, adaptive loading Pinyin::useSmart(); // Auto Strategy - automatically selects the best strategy for your environment Pinyin::useAutoStrategy(); // Clear cache when needed (useful in long-running processes) Pinyin::clearCache();
❤️ 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
overtrue/laravel-pinyin 适用场景与选型建议
overtrue/laravel-pinyin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 607.07k 次下载、GitHub Stars 达 531, 最近一次更新时间为 2015 年 03 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「Chinese」 「Pinyin」 「overtrue」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 overtrue/laravel-pinyin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 overtrue/laravel-pinyin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 overtrue/laravel-pinyin 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
简繁体转换.
An anti-pattern tools to have Translations stored in single column.
Parser for CC-CEDICT Chinese-English dictionary
Alfabank REST API integration
中国农历转换与查询工具
Support Chinese username and lower min characters to 2.
统计信息
- 总下载量: 607.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 542
- 点击次数: 37
- 依赖项目数: 15
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-15