-
-
- /**
- 人民元金額を中国語の大文字に変換
- リンク: bbs.it-home.org
- 日付: 2013-2-28
- */
- function cny($ns) {
- static $cnums=array("zero","壹","谰","三","四","五","鲁","撒","八","九"),
- $cnyunits=array("circle","angle","fen"),
- $grees =array("十","百","千","万","十","百","千","万");
- list($ns1,$ns2)=explode(". ",$ns,2);
- $ns2=array_filter(array($ns2[1],$ns2[0]));
- $ret=array_merge($ns2,array(implode("",_cny_map_unit(str_split( $ns1),$grees)),""));
- $ret=implode("",array_reverse(_cny_map_unit($ret,$cnyunits))));
- return str_replace(array_keys($cnums),$cnums, $ ret);
- }
function _cny_map_unit($list,$units) {
- $ul=count($units);
- $xs=array();
- foreach (array_reverse($ list ) as $x) {
- $l=count($xs);
- if ($x!="0" || !($l%4)) $n=($x=='0'?' ' :$x).($units[($l-1)%$ul]);
- else $n=is_numeric($xs[0][0])?$x:'';
- array_unshift($xs , $n);
- }
- return $xs;
- }
- ?>
-
コードをコピー
使用法: 数値パラメータを直接渡す
次の例では、大文字の数字を出力し、結果を出力します: 1,000,2,01121 元
|