1 Star 0 Fork 66

shaten / php-pinyin

forked from mz / php-pinyin 
Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README

#php-pinyin

php 无组件支持中文汉字转拼音单元(支持生僻字)。

之前用的汉字转拼音单元 已经不能满足需求了,自己重新整理+优化了一下。

方式:先用 gbk 判断码表,取不到的字用生僻字字典。

(需要 php-mb_string 扩展支持)

方法:

class pinyin{

    // $str : 需要转换的汉字(只支持utf-8)
    // $first_char : 是否只取首字母
    // $split_char : 生成每个字间的分隔符
    // $except_char : 排除字符,防止被过滤掉
static function get($str, $first_char = 0, $split_char = '', $except_char = '');

}

例:

$str = '是默认的编码方式。对于英文文件是ASCII编码,对于简体中文文件是GB2312编码,魍魉,交媾,蒯草';

// 默认模式

pinyin::get($str);

// 全拼音+带分隔线

pinyin::get($str, 0, '-');

// 拼音字母+带分隔线

pinyin::get($str, 1, '-');

已知问题

  1. 多音字未处理, 重庆 会被转成 zhongqing

词典工具使用

生成无法识别的文字方法: 打开keywords.txt,将字典放至keyword.txt, 保存为 utf-8 编码。 然后,cmd运行: php make.php find 这个候,我们用记事本或者编辑器打开new_dict.txt, 看到无法识别的文字如下,如果没有无法识别的就不会有内容(举例):



...

那么,我们手工将对应的拼音写在文字后边,用空格格开:

阿 a
啊 a
...

最后,运行:php make.php make 这样,pinyin.class.php 就会有新加入的字典了 我们拷贝新的 pinyin.class.php 去项目就可以识别之前不能识别的字了。

Empty file

About

php 汉字转拼音单元(支持生僻字) expand collapse
PHP
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
PHP
1
https://gitee.com/shaten/php-pinyin.git
git@gitee.com:shaten/php-pinyin.git
shaten
php-pinyin
php-pinyin
master

Search