优雅的简繁体转换OpenCC

WBOY
Release: 2016-06-23 13:31:33
Original
2003 people have browsed it

介绍

opencc4php 是OpenCC的PHP扩展,能很智能的完成简繁体转换

转换效果:你干什么不干我事=>你?什?不干我事

地区词汇转换效果:我鼠标哪儿去了=>我滑鼠哪?去了

安装

你需要先安装1.0.1版本以上的OpenCC,安装OpenCC:

git clone https://github.com/BYVoid/OpenCC.gitcd OpenCCmakesudo make install
Copy after login

安装opencc4php:

git clone [email protected]:NauxLiu/opencc4php.gitcd opencc4phpphpize./configuremake && sudo make install
Copy after login

如果你的OpenCC安装目录不在/usr或/usr/local,可在./configure时添加--with-opencc=[DIR]指定你的OpenCC目录

使用

实例:

$od = opencc_open("s2twp.json"); //传入配置文件名$text = opencc_convert("我鼠标哪儿去了。", $od);echo $text;opencc_close($od);
Copy after login

输出:我滑鼠哪?去了

函数列表:

opencc_open(string ConfigName)ConfigName:配置文件名,成功返回资源对象,失败返回false
opencc_close(resource ob)关闭资源对象,成功返回true,失败返回false. 成功后od会置为NULL
opencc_error()返回最后一条错误信息,有错误信息返回String,无错误返回false
opencc_convert(string str, resource od)str:要转换的字符串(UTF-8),od:opencc资源对象

可用配置

  • s2t.json简体到繁体
  • t2s.json繁体到简体
  • s2tw.json简体到台湾正体
  • tw2s.json台湾正体到简体
  • s2hk.json简体到香港繁体(香港小学学习字词表标准)
  • hk2s.json香港繁体(香港小学学习字词表标准)到简体
  • s2twp.json简体到繁体(台湾正体标准)并转换为台湾常用词汇
  • tw2sp.json繁体(台湾正体标准)到简体并转换为中国大陆常用词汇

项目主页:http://www.open-open.com/lib/view/home/1435906052075

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!