Yii Framework Forum: YII HanziTools 汉字中文业务处理 - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

YII HanziTools 汉字中文业务处理 YII 汉字简体,繁体,拼音,数字大小写转换 Rate Topic: -----

#1 User is offline   jiania 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 25-October 09

Posted 08 December 2009 - 03:48 AM

本扩展基于google code pzpinyin项目修改的:) 方便大家处理一些常用的汉字处理用.





Yii::import('application.extensions.Hanzi.HanziTools');
$pzt = new HanziTools();

// prints 'hello world' in Chinese
echo $hello_world = "世界你好";



// prints 'hello world' in hanyu pinyin -- shi4 jie4 ni3 hao3
echo $got_pinyin = $pzt->pzhanzi_hanzi_to_pinyin($hello_world);

// prints 'hello world' in hanyu pinyin -- sjni
echo $pzt->getShortPinyin('世界你好');

// prints 'hello world' in hanyu pinyin with tone marks -- shì jiè nĭ hăo
echo $got_tonemarks = $pzt->pzpinyin_tonedisplay_convert_to_mark($got_pinyin);

echo "<p>";

// prints 'hello world' in zhuyin fuhao -- ㄕˋ ㄐㄧㄝˋ ㄋㄧˇ ㄏㄠˇ
echo $got_zhuyin = $pzt->pzpinyin_pinyintype_hanyu_pinyin_to_zhuyin($got_pinyin);

echo "<p>";

// prints 'hello world' in tongyong pinyin -- shih4 jie4 ni3 hao3
echo $got_tongyong = $pzt->pzpinyin_pinyintype_hanyu_pinyin_to_tongyong_pinyin($got_pinyin);


echo "<p>";

// prints 'hello world' in mandarin yale -- shr4 jye4 ni3 hau3
echo $got_zhuyin = $pzt->pzpinyin_pinyintype_hanyu_pinyin_to_yale($got_pinyin);


echo "<p>";

// prints 'happy to meet you' in Traditional Chinese -- 很高興認識你
echo $happy_to_meet_you = "很高興認識你";

echo "<p>";

// prints 'happy to meet you' in Simplified Chinese -- 很高兴认识你
echo $pzt->pzhanzi_traditional_to_simplified($happy_to_meet_you);

echo "<p>";




# sample line from CEDICT file
$line = "安頓 安顿 [an1 dun4] /find a place for/help settle down/arrange for/undisturbed/peaceful/";

print_r($pzt->pzcedict_entry_getvalues($line, TRUE));








// positive and negative numbers
echo "<p>";echo $pzt->pznumbers_go("33"); // 三十三
echo "<p>";echo $pzt->pznumbers_go("-58"); // 負五十八
echo "<p>";echo $pzt->pznumbers_go("8888"); // 八千八百八十八
echo "<p>";echo $pzt->pznumbers_go("10538"); // 一萬〇五百三十八
echo "<p>";echo $pzt->pznumbers_go("-99291"); // 負九萬九千二百九十一


// big positive and negative numbers
echo "<p>";echo $pzt->pznumbers_go("100000000"); // 一億
echo "<p>";echo $pzt->pznumbers_go("888384848"); // 八億八千八百三十八萬四千八百四十八
echo "<p>";echo $pzt->pznumbers_go("8800980088"); // 八十八億九十八萬〇八十八


// long dates
echo "<p>";echo $pzt->pznumbers_go("August 8, 2008"); // 二〇〇八年八月八日
echo "<p>";echo $pzt->pznumbers_go("October 1, 1949"); // 一九四九年十月一日


// short dates dates MM/DD/YYYY or YYYY/MM/DD
echo "<p>";echo $pzt->pznumbers_go("2008/01/20"); // 二〇〇八年一月二十日
echo "<p>";echo $pzt->pznumbers_go("08-20-2005"); // 二〇〇五年八月二十日
echo "<p>";echo $pzt->pznumbers_go("08.20.2005"); // 二〇〇五年八月二十日


// just translating the year alone
echo "<p>";echo $pzt->pznumbers_go("year 2008"); // 二〇〇八年
echo "<p>";echo $pzt->pznumbers_go("year 1932"); // 一九三二年
echo "<p>";echo $pzt->pznumbers_go("year 2012"); // 二〇一二年


// money, money, money
echo "<p>";echo $pzt->pznumbers_go("$2.22"); // 兩塊兩毛兩分
echo "<p>";echo $pzt->pznumbers_go("$0.25"); // 兩毛五分
echo "<p>";echo $pzt->pznumbers_go("$888,888.32"); // 八十八萬八千八百八十八塊三毛兩分
echo "<p>";echo $pzt->pznumbers_go("$89985.62"); // 八萬九千九百八十五塊六毛兩分


// time, tick! tock!
echo "<p>";echo $pzt->pznumbers_go("5:09"); // 上午五點九分
echo "<p>";echo $pzt->pznumbers_go("8:32"); // 上午八點三十二分
echo "<p>";echo $pzt->pznumbers_go("13:59"); // 下午一點五十九分

// time with AM or PM
echo "<p>";echo $pzt->pznumbers_go("2:09 am"); // 上午兩點九分 ** space is ok between time and am/pm
echo "<p>";echo $pzt->pznumbers_go("2:12pm"); // 下午兩點十二分



// fractions
echo "<p>";echo $pzt->pznumbers_go("3/5"); // 五分之三
echo "<p>";echo $pzt->pznumbers_go("8/9"); // 九分之八
echo "<p>";echo $pzt->pznumbers_go("-3/8"); // 負八分之三


// decimals
echo "<p>";echo $pzt->pznumbers_go("8.29"); // 八點二九
echo "<p>";echo $pzt->pznumbers_go("3.14"); // 三點一四
echo "<p>";echo $pzt->pznumbers_go("-9.68"); // 負九點六八


// percents
echo "<p>";echo $pzt->pznumbers_go("98%"); // 百分之九十八
echo "<p>";echo $pzt->pznumbers_go("32%"); // 百分之三十二
echo "<p>";echo $pzt->pznumbers_go("-3%"); // 負百分之三
0

#2 User is offline   jerry2801 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 504
  • Joined: 18-November 09

Posted 08 December 2009 - 05:32 AM

不错~

建议分享到 extendsions 去~
0

#3 User is offline   hiscaler 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 230
  • Joined: 17-October 09

Posted 08 December 2009 - 10:01 AM

very good.很实用的东东。
0

#4 User is offline   yiqing95 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 602
  • Joined: 27-December 10
  • Location:china

Posted 30 March 2013 - 11:10 AM

时隔三四年 依旧好用呵呵 :lol:
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users