如果要用於金額的轉換,小數部分的處理要做一下修改
function ch_num($num,$mode=true) {
$char = array("零" , "壹","貳","叁","肆","伍","陸","柒","捌","玖");
$dw = array("","拾","佰","仟","","萬","億","兆");
$dec = "點";
$retval = "";
if ( $mode)
preg_match_all("/^0*(d*).?(d*)/",$num, $ar);
else
preg_match_all("/(d*). ? (d*)/",$num, $ar);
if($ar[2][0] != "")
$retval = $dec . ch_num($ar[2][ 0 ],false); //若有小數,先遞歸處理小數
if($ar[1][0] != "") {
$str = strrev($ar[1][0 ] );
for($i=0;$i
if ($mode) {
$out[$i] .= $str[$i] != "0"? $dw[$i%4] : "";
if($str[$ i ]+$str[$i-1] == 0)
$out[$i] = "";
if($i%4 == 0)
$out[$i] . = $dw[4+floor($i/4)];
}
}
$retval = join("",array_reverse($out)) . $retval;
}
return $retval;
}
//echo ch_num("12345006789001.123");
//echo ch_num("880079.1234");
以上就介紹了阿拉伯數字字體 php下實現一個阿拉伯數字轉中文數字的函數,包括了阿拉伯數字字體方面的內容,希望對PHP教程有興趣的朋友有所幫助。