女士们先生们,早上好。

今天给大家带来的是文字处理类库:汉语拼音PHP类库!

汉字是拼音类(拼写和首字母),这是以前在网上收集的汉语拼音类,这个比较好用。现在和大家分享!

因为代码比较长,需要文件版的人可以私下和我谈谈!

好吧,废话不要多说源代码!

?嗯?PHP

/* *

* Created by PhpStorm .

* User: jifei

* Date: 15/6/25

* Time:下午2:26

*/

Class Pinyin

{

//中文字符串

Private static $ string=

//拼音

Private static $ pinyin=

private static $ encoding=' UTF-8 '

//短拼音

Private static $ short _ pinyin=

//单汉字拼音词典

Private static $dic=array(

“腌菜”=“风筝”,

啊'='a '

强制'='po '

'痛苦'='ai '

'孩子'='ai '

' ail '=' ai ail '

哈克'='ai '

Armadillo '='安'

AO '=' AO '

' u '=' ao '

《小戏》=《纽埃》,

“岘港”=“AO”,

AO '=' AO '

'扒手'='ba '

“诗”=“酒吧”,

'弹性'='pa '

' '='ba '

“莫名其妙”=“一半”,

肩膀'='pang '

磅'='bang '

'总计'='pao '

曝光'='pu '

'大败'='pao '

“瀑布”=“pu”,

“之间”=“雨”,

10-。='pi '

' '='bei '

'味道'='bei '

' polo '=' Bei '

Luang '=' Bei '

“雨”=“雨”,

'是的'='本'

' '='beng '

‘船夫’=‘雨’,

“秘密”=“美”,

提供'='pi '

“分泌”=“美”,

'炮台'='bi '

“啊”=“雨”,

`

;笾' => 'bian',

'扁' => 'bian',

'碥' => 'bian',

'窆' => 'bian',

'便' => 'bian',

'弁' => 'bian',

'缏' => 'bian',

'骠' => 'biao',

'杓' => 'shao',

'飚' => 'biao',

'飑' => 'biao',

'瘭' => 'biao',

'髟' => 'biao',

'玢' => 'bin',

'豳' => 'bin',

'镔' => 'bin',

'膑' => 'bin',

'屏' => 'ping',

'泊' => 'bo',

'逋' => 'bu',

'晡' => 'bu',

'钸' => 'bu',

'醭' => 'bu',

'埔' => 'pu',

'瓿' => 'bu',

'礤' => 'ca',

'骖' => 'can',

'藏' => 'cang',

'艚' => 'cao',

'侧' => 'ce',

'喳' => 'zha',

'刹' => 'sha',

'鲳' => 'chang',

'长' => 'chang',

'苌' => 'chang',

'氅' => 'chang',

'鬯' => 'chang',

'焯' => 'chao',

'朝' => 'chao',

'车' => 'che',

'琛' => 'chen',

'谶' => 'chen',

'榇' => 'chen',

'蛏' => 'cheng',

'埕' => 'cheng',

'枨' => 'cheng',

'塍' => 'cheng',

'裎' => 'cheng',

'螭' => 'chi',

'眵' => 'chi',

'墀' => 'chi',

'篪' => 'chi',

'坻' => 'di',

'瘛' => 'chi',

'种' => 'zhong',

'重' => 'zhong',

'仇' => 'chou',

'帱' => 'chou',

'俦' => 'chou',

'雠' => 'chou',

'臭' => 'chou',

'楮' => 'chu',

'畜' => 'chu',

'嘬' => 'zuo',

'膪' => 'chuai',

'巛' => 'chuan',

'椎' => 'zhui',

'呲' => 'ci',

'兹' => 'zi',

'伺' => 'si',

'璁' => 'cong',

'楱' => 'cou',

'攒' => 'zan',

'爨' => 'cuan',

'隹' => 'zhui',

'榱' => 'cui',

'撮' => 'cuo',

'鹾' => 'cuo',

'嗒' => 'da',

'哒' => 'da',

'沓' => 'ta',

'骀' => 'tai',

'绐' => 'dai',

'埭' => 'dai',

'甙' => 'dai',

'弹' => 'dan',

'澹' => 'dan',

'叨' => 'dao',

'纛' => 'dao',

'簦' => 'deng',

'提' => 'ti',

'翟' => 'zhai',

'绨' => 'ti',

'丶' => 'dian',

'佃' => 'dian',

'簟' => 'dian',

'癜' => 'dian',

'调' => 'tiao',

'铞' => 'diao',

'佚' => 'yi',

'堞' => 'die',

'瓞' => 'die',

'揲' => 'die',

'垤' => 'die',

'疔' => 'ding',

'岽' => 'dong',

'硐' => 'dong',

'缍' => 'duo',

'锷' => 'e',

'鹗' => 'e',

'阏' => 'e',

'诶' => 'ea',

'鲕' => 'er',

'珥' => 'er',

'佴' => 'er',

'番' => 'fan',

'彷' => 'pang',

'霏' => 'fei',

'蜚' => 'fei',

'鲱' => 'fei',

'芾' => 'fei',

'瀵' => 'fen',

'鲼' => 'fen',

'否' => 'fou',

'趺' => 'fu',

'桴' => 'fu',

'莩' => 'fu',

'菔' => 'fu',

'幞' => 'fu',

'郛' => 'fu',

'绂' => 'fu',

'绋' => 'fu',

'祓' => 'fu',

'砩' => 'fu',

'黻' => 'fu',

private static function mbStringToArray($string)

{

$stop = mb_strlen($string, 'utf-8');

$result = array();

for ($idx = 0; $idx < $stop; $idx++) {

$result[] = mb_substr($string, $idx, 1, 'utf-8');

}

return $result;

}

/**

* 汉字转拼音

* @param $string

* @param $encoding

*/

private static function chineseToPinyin($string, $encoding)

{

$words = self::mbStringToArray(mb_convert_encoding($string, 'utf-8', $encoding));

self::$string = $string;

self::$encoding = $encoding;

self::$pinyin = '';

self::$short_pinyin = '';

foreach ($words as $v) {

if (isset(self::$dic[$v])) {

$tmp = self::$dic[$v];

} else {

$tmp = $v;

}

self::$pinyin .= $tmp;

self::$short_pinyin .= mb_substr($tmp, 0, 1, $encoding);

}

}

/**

* 获取拼音

* @param $string

* @param string $encoding

* @return string

*/

public static function getPinyin($string, $encoding = 'utf-8')

{

if ($string != self::$string || $encoding != self::$encoding) {

self::chineseToPinyin($string, $encoding);

}

return self::$pinyin;

}

/**

* 获取拼音缩写

* @param $string

* @param string $encoding

* @return string

*/

public static function getShortPinyin($string, $encoding = 'utf-8')

{

if ($string != self::$string || $encoding != self::$encoding) {

self::chineseToPinyin($string, $encoding);

}

return self::$short_pinyin;

}

}

相关推荐