php如何让阿拉伯数字转换为中文数字
发布网友
发布时间:2022-04-06 04:43
我来回答
共5个回答
热心网友
时间:2022-04-06 06:12
如果要用于金额的转换,对小数部分的处理要做一下修改
<?php
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<strlen($str);$i++) {
$out[$i] = $char[$str[$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");
echo ch_num("300045.0123");
?>
热心网友
时间:2022-04-06 07:30
$array = array(1=>"一","二","三","四","五","六","七","八","九","十");
foreach($array as $key => $value) {
echo $value
}//$key是数字,$value是中文,随你输出哪样
如果你要更详细的,数字更大的,这里有,不过有点小错误,修改下不影响,思路在了,望采纳
http://www.xssep.com/view-137.html
热心网友
时间:2022-04-06 09:05
只能通过数组这样
<?php
$array = array('一','二','三','四','五','六','七','八','九','十');
for($a =1;$a<=10;$a++){
echo $array[$a-1];
}
?>
热心网友
时间:2022-04-06 10:56
<?php
$i = array("一","二","三","四","五","六","七","八","九");
for($a=1;$a<=$i.length;$a++){
echo"循环".$i[a]."<br />";}
?>
热心网友
时间:2022-04-06 13:04
好像有个函数可以,找一下,我忘了