tekintian/pinyin_utils
Composer 安装命令:
composer require tekintian/pinyin_utils
包简介
汉字转拼音工具,支持自定义转换方式[全拼,首字母,第一个字母], 支持自定义拼音字典,目前提供2个拼音字典,精简版共收录9千多常用汉字,完整版共收录20902个基本汉字+5059生僻字。
README 文档
README
目前最全面的汉字词典
包含20902个基本汉字+5059生僻字
使用方法:
- 载入本工具类
composer require tekintian/pinyin_utils
- 使用本工具
<?php // 载入自动加载: 如果使用框架的话这个步骤可以忽略。 require_once __DIR__ . '/vendor/autoload.php'; use \tekintian\pinyin_utils\Pinyin; // 拼音转换测试 $py = Pinyin::convert("云南网"); echo $py;
sources
How to autoload the PSR-4 way?
PSR-4 is the newest standard of autoloading in PHP, and it compels us to use namespaces.
We need to take the following steps in order to autoload our classes with PSR-4:
a. Put the classes that we want to autoload in a dedicated directory. For example, it is customary to convene the classes that we write into a directory called src/, thus, creating the following folder structure:
your-website/
src/
Db.php
Page.php
User.php
b. Give the classes a namespace. We must give all the classes in the src/ directory the same namespace. For example, let's give the namespce Acme to the classes. This is what the Page class is going to look like:
<?php namespace Acme; class Page { public function __construct() { echo "hello, i am a page."; } }
We give the same namespace Acme to all of the classes in the src/ directory. c. Point the namespace to the src/ directory in the composer.json file . We point the directory that holds the classes to the namespace in the composer.json file. For example, this is how we specify in the composer.json file that we gave the namespace Acme to the classes in the src/ directory:
{
"autoload": {
"psr-4": {
"Acme\\":"src/"
}
}
}
-
We use the psr-4 key.
The namespace Acme points to the src/ directory. The namespace has to end with \. For example, "Acme\". You can replace the generic Acme with the name of your brand or website.
d. Update the Composer autoloader:
$ composer dumpautoload -o
e. Import the namespace to your scripts. The scripts need to import the namespace as well as the autoloader, e.g., index.php:
<?php require "vendor/autoload.php"; use Acme\Db; use Acme\User; use Acme\Page; $page1 = new Page();
How to autoload if the directory structure is complex? Up till now, we demonstrated autoloading of classes that are found directly underneath the src/ folder, but how can we autoload a class that is found in a subdirectory? For example, we may want to move the Page class into the Pages directory and, thus, create the following directory tree:
your-website/
src/
Db.php
User.php
Pages/
Page.php
These are the steps that we need to follow: a. Redefine the namespace. We need to give the Page class a namespace in accordance with its new location in the src/Pages directory.
<?php namespace Acme\Pages; public class Page { function __construct() { echo "hello, i am a page."; } }
b. Use the namespaces in the scripts:
<?php require "vendor/autoload.php"; use Acme\Db; use Acme\User; use Acme\Pages\Page; $page1 = new Page();
Conclusion
As we demonstrated in the last two tutorials, Composer is a powerful tool that can help us to both manage and autoload our own classes as well as others. Now, that we have such a powerful tool under our belt we're entitled to fully enjoy the best that modern-day PHP has to offer!
https://phpenthusiast.com/blog/how-to-autoload-with-composer https://phpenthusiast.com/object-oriented-php-tutorials
tekintian/pinyin_utils 适用场景与选型建议
tekintian/pinyin_utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 98 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 01 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「工具」 「汉字转�」 「音」 「汉字工具」 「汉字转�」 「音工具」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tekintian/pinyin_utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tekintian/pinyin_utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tekintian/pinyin_utils 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
目前最全面的地理坐标转换工具,支持GPS坐标 WGS-84,百度坐标 BD-09,国测局 火星坐标GCJ-02之间的相互转换
thinkphp实用程序
现代化的 PHP 工具包,包含强大的 DOM 操作库、数据转换和一些常用的类库、HTTP网络请求、代码压缩、通用函数集和实用工具等
开发人员工具
常用函数集
超级灵活,强大,可自定义的curl http请求类, 可伪装来源,agent, 伪装IP地址等等,支持POST, GET等方式
统计信息
- 总下载量: 98
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2019-01-21