All Projects → bullsoft → Php Pinyin

bullsoft / Php Pinyin

A PHP extension converting Chinese characters to Pinyin

Programming Languages

cpp11
221 projects

Projects that are alternatives of or similar to Php Pinyin

Baidupcs Go
百度网盘客户端 - Go语言编写
Stars: ✭ 23,925 (+28725.3%)
Mutual labels:  baidu
Baidupankey
在线查询网盘提取码 求职呀,有大佬内推吗
Stars: ✭ 947 (+1040.96%)
Mutual labels:  baidu
Python Pisces
A tools to search for and download images by keywords using search engines: google/baidu/yahoo/bing. 使用google等搜索引擎搜索关键词并下载图片
Stars: ✭ 60 (-27.71%)
Mutual labels:  baidu
Mtrans
Multi-source Translation
Stars: ✭ 711 (+756.63%)
Mutual labels:  baidu
Baidu Pet Chain Helper
百度莱茨狗小工具,chrome 插件
Stars: ✭ 26 (-68.67%)
Mutual labels:  baidu
Rocket
NetDisk in command line.
Stars: ✭ 40 (-51.81%)
Mutual labels:  baidu
Paddle Lite
Multi-platform high performance deep learning inference engine (『飞桨』多平台高性能深度学习预测引擎)
Stars: ✭ 5,808 (+6897.59%)
Mutual labels:  baidu
Xinahn Socket
一个开源,高隐私,自架自用的聚合搜索引擎。 https://xinahn.com
Stars: ✭ 77 (-7.23%)
Mutual labels:  baidu
Pinyin
汉字转带有声调的汉语拼音,汉字转无声调的汉语拼音,汉字转成汉语拼音首字母,获取英文姓名首字母,获取中文名
Stars: ✭ 27 (-67.47%)
Mutual labels:  pinyin
Yavipcore
Net Core Music Interface
Stars: ✭ 1,095 (+1219.28%)
Mutual labels:  baidu
Redis Search
Deprecated! High performance real-time prefix search, indexes store in Redis for Rails application
Stars: ✭ 713 (+759.04%)
Mutual labels:  pinyin
Go Pinyin
汉字转拼音
Stars: ✭ 907 (+992.77%)
Mutual labels:  pinyin
Socialite
Socialite is an OAuth2 Authentication tool. It is inspired by laravel/socialite, you can easily use it without Laravel.
Stars: ✭ 1,026 (+1136.14%)
Mutual labels:  baidu
Xpinyin
Translate Chinese hanzi to pinyin (拼音) by Python, 汉字转拼音
Stars: ✭ 709 (+754.22%)
Mutual labels:  pinyin
Image Downloader
Download images from Google, Bing, Baidu. 谷歌、百度、必应图片下载.
Stars: ✭ 1,173 (+1313.25%)
Mutual labels:  baidu
Pinyin
🇨🇳 汉字拼音 ➜ hàn zì pīn yīn
Stars: ✭ 6,047 (+7185.54%)
Mutual labels:  pinyin
Web Oauth App
第三方登录服务 Web OAuth 示例
Stars: ✭ 30 (-63.86%)
Mutual labels:  baidu
Php Sdk
百度AI开放平台 PHP SDK
Stars: ✭ 81 (-2.41%)
Mutual labels:  baidu
Rime pure
【rime小狼毫\trime同文】手机/PC一站式配置【简约皮肤\拼音搜狗词库\原创trime同文四叶草九宫格拼音方案\四叶草拼音、小鹤双拼、极品五笔、徐码、郑码】 rime配置
Stars: ✭ 73 (-12.05%)
Mutual labels:  pinyin
L Passport
Koa middleware and api sdk for wechat oauth, qq oauth, baidu oauth and weibo oauth
Stars: ✭ 52 (-37.35%)
Mutual labels:  baidu

php-pinyin

A PHP extension converting Chinese characters to Pinyin.

一个来自百度的汉字转拼音PHP扩展,其他的汉字转拼音方案存在两个问题:

  1. 可转的汉字数有限,几千个左右
  2. 不能解决多音字问题

Installation

Currently you have two ways to use php-pinyin. One depends on PHP-CPP, while another one is plain php extenstion which works with php 7.x. (For php 5.x support, please checkout the branch legacy)

Method with PHP-CPP

Main improvements:

  • Depend PHP-CPP, an awesome library which wrapper Zend Engine with friendly api
  • Support PHP 7
  • This time we support UTF-8 and GBK encoding
  • Add ini_setting (pinyin.dict_path and pinyin.dict_tone), you shoud not loadDict yourself.

Install

  1. Install PHP-CPP or its LEGACY Version. Before that, you need to change the Makefile,,, because PHP-CPP was written with C++11, but libpinyin was written with C++98,,, So you should build PHP-CPP with -D_GLIBCXX_USE_CXX11_ABI=0 option, which means "Do not use Cxx11's Application Binary Interface"
  2. cd /path/to/php-pinyin/cpp-ext
  3. make
  4. make install

Method without PHP-CPP

This is upgraded from old php-pinyin for php 5.x.

Install

  1. cd /path/to/php-pinyin/ext
  2. /path/to/php/bin/phpize
  3. ./configure --with-php-config=/path/to/php/bin/php-config --with-baidu-pinyin=/path/to/pinyin
  4. make
  5. make install

Here /path/to/pinyin is the directory where you copied libpinyin to.

Usage

$obj  = new Pinyin();

// UTF-8
var_dump($obj->convert("重庆重量"));
var_dump($obj->multiConvert(array("重庆南京市长江大桥财务会议会计")));

// GBK
var_dump($obj->multiConvert(array(iconv("UTF-8", "GBK", "重庆"), iconv("UTF-8", "GBK", "重量"))));

Results will be:

string(22) "chong'qing'zhong'liang"
array(1) {
  [0] =>
  string(65) "chong'qing'nan'jing'shi'chang'jiang'da'qiao'cai'wu'hui'yi'kuai'ji"
}
array(2) {
  [0] =>
  string(10) "chong'qing"
  [1] =>
  string(11) "zhong'liang"
}
array(1) {
  [0] =>
  string(29) "zhong'hua'ren'min'gong'he'guo"
}

If you want to get the Abbr. of the whole pinyin-string, you can simply do this:

echo preg_replace("/\'([a-zA-Z])[0-9a-zA-Z]*/e", "strtoupper('$1')", "'".$py_string);

This lib only support Chinese characters and english letters, or else it will return false. So you can write a safeConvert function to avoid this.

$p = new Pinyin();
function safeConvert($word, $pyOnly = true) {
    global $p;
    // UTF-8 regex for Chinese
    $result = preg_match_all("/([\x{4e00}-\x{9fa5}]+)/iu", $word, $matches);
    if(!$result) {
        throw new \Exception("No Chinese characters in word");
    }

    $pys = $p->multiConvert($matches[1]);
    if($pyOnly == true) {
        return implode("'", $pys);
    } else {
        return str_replace($matches[1], $pys, $word);
    }
}

If you want to customize dict-files yourself and then convert them to binary-format again, do it like this:

$result = $obj->generateDict("/home/work/local/pinyin/dict/dict.txt", "/home/work/tmp/dict.dat");

if($result) echo "Generate complete";

Feedback

Issues and contributions are welcome.

Thank you!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].