PHP中文转拼音类库overtrue/pinyin:基于 CC-CEDICT 词典的中文转拼音工具,更准确的支持多音字的汉字转拼音解决方案。
基于 CC-CEDICT 词典的中文转拼音工具,更准确的支持多音字的汉字转拼音解决方案。
PHP中文转拼音类库overtrue/pinyin
在使用PHP开发系统,经常用到中文转拼音类库,以下演示在使用ThinkPHP5/6等开发系统的时,overtrue/pinyin如何使用。
在ThinkPHP5下演示如何使用:
ThinkPHP5等框架安装略过:
在项目更目录下安装依赖:
使用 Composer 安装:
$ composer require "overtrue/pinyin:~4.0"
$ composer require "overtrue/pinyin:~4.0"
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing overtrue/pinyin (4.0.6): Loading from cache
Writing lock file
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!
安装完依赖如下图:
在控制器中直接引入:
<?php
namespace app\index\controller;
use Overtrue\Pinyin\Pinyin;
class Index
{
public function index()
{
echo "This is ThinkPHP5.1";
}
public function pinyin()
{
// 小内存型
$pinyin = new Pinyin(); // 默认
$result = $pinyin->convert('带着希望去旅行,比到达终点更美好');
var_dump(implode(' ', $result));
}
}
看一下效果:
string(61) "dai zhe xi wang qu lyu xing bi dao da zhong dian geng mei hao"
浏览器查看:github.com/overtrue/pinyin
转载注明:
感谢博主,喝杯咖啡~
感谢博主,喝杯咖啡~
还没有人发表评论