easyconn/chinese

中文繁简转换 Convert Traditional and Simplified Chinese

1.0.0 2020-03-13 02:47 UTC

This package is auto-updated.

Last update: 2024-09-13 12:43:32 UTC


README

PHP 中文转换,简单,轻量(v0.2 与 WikiMedia Library 一起小于 400KB)

安装

使用 Composer

composer require steelywing/chinese

手动安装

  • 克隆此仓库

    git clone https://github.com/steelywing/PHP-Chinese.git
    
  • 生成 autoload.php,在 PHP-Chinese 文件夹中运行

    composer dump-autoload
    

特性

  • 使用 WikiMedia 或 OpenCC 库
  • 轻量级
  • 使用最长匹配规则

示例

更多用法,请参阅 demo.php

require_once __DIR__ . '/vendor/autoload.php';

use SteelyWing\Chinese\Chinese;

$chinese = new Chinese();

echo $chinese->to(Chinese::ZH_HANS, '轉成簡體中文'); // 转成简体中文
echo $chinese->to(Chinese::ZH_HANT, '转成繁体中文'); // 轉成繁體中文

切换库

切换到 OpenCC,在 dict 文件夹中运行以下命令

git clone https://github.com/BYVoid/OpenCC.git
php import_opencc.php

切换到 WikiMedia,在 dict 文件夹中运行以下命令

php import_wikimedia.php

许可证

MIT

WikiMedia 许可证

OpenCC 许可证