<?php
header("Content-Type:text/html;charset=utf-8"); function num_to_upper($num)
{
$d = array('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
$e = array('元','拾','佰','仟','万','拾万','佰万','仟万','亿','拾亿','佰亿','仟亿','万亿');
$p = array('分','角');
$zheng='整'; //追加"整"字
$final = array(); //结果
$inwan=0; //是否有万
$inyi=0; //是否有亿
$len_pointdigit=0; //小数点后长度
$y=0;
if($c = strpos($num, '.')) { //有小数点,$c为小数点前有几位数
$len_pointdigit = strlen($num)-strpos($num, '.')-1; // 判断小数点后有几位数
if($c>13) { //简单的错误处理
echo "数额太大,已经超出万亿.";
die();
} elseif($len_pointdigit>2) { //$len_pointdigit小数点后有几位
echo "小数点后只支持2位.";
die();
}
} else { //无小数点
$c = strlen($num);
$zheng = '整';
}
for($i=0;$i<$c;$i++) { //处理整数部分
$bit_num = substr($num, $i, 1); //逐字读取 左->右
if($bit_num!=0 || substr($num, $i+1, 1)!=0) //当前是零 下一位还是零的话 就不显示
@$low2chinses = $low2chinses.$d[$bit_num];
if($bit_num || $i==$c-1)
@$low2chinses = $low2chinses.$e[$c-$i-1];
}
for($j=$len_pointdigit; $j>=1; $j--) { //处理小数部分
$point_num = substr($num, strlen($num)-$j, 1); //逐字读取 左->右
if($point_num != 0)
@$low2chinses = $low2chinses.$d[$point_num].$p[$j-1];
// if(substr($num, strlen($num)-2, 1)==0 && substr($num, strlen($num)-1, 1)==0) //小数点后两位都是0
}
$chinses = str_split($low2chinses,2); //字符串转换成数组
//print_r($chinses);
for($x=sizeof($chinses)-1;$x>=0;$x--) { //过滤无效的信息
if($inwan==0&&$chinses[$x]==$e[4]) { //过滤重复的"万"
$final[$y++] = $chinses[$x];
$inwan=1;
}
if($inyi==0&&$chinses[$x]==$e[8]) { //过滤重复的"亿"
$final[$y++] = $chinses[$x];
$inyi=1;
$inwan=0;
}
if($chinses[$x]!=$e[4]&&$chinses[$x]!=$e[8]) //进行整理,将最后的值赋予$final数组
$final[$y++] = $chinses[$x];
}
$newstring=(array_reverse($final)); //$final为倒数组,$newstring为正常可以使用的数组
$nstring=join($newstring); //数组变成字符串
if(substr($num,-2,1)==0 && substr($num,-1)<>0) { //判断原金额角位为0 ? 分位不为0 ?
$nstring=substr($nstring,0,(strlen($nstring)-4))."零".substr($nstring,-4,4); //这样加一个零字
}
$fen="分";
$fj=substr_count($nstring, $fen); //如果没有查到分这个字
return $nstring=($fj==0)?$nstring.$zheng:$nstring; //就将"整"加到后面
} echo num_to_upper(1234.56); ?>
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANsAAABICAIAAADwExf6AAAM7klEQVR4nO2d/XMbxRnH7+/ptNVMS2kpUGgpDEMDJcNbgSgNzgvBJKEmNIXQEDNQUvWHKgktQ0iigIPFyBbHCdlJHL1EliynTmLFjiW5ih3JcmxZL0bWSU5sSWHcH8467e3u7Z1kub4k+53nB2u1++ze7kfPvsizYmb4EmgTmXnWdZE7dyk6w2cKZZUWTxe6vJetjoFYugA5pEatJmNmciXRRuPfmbv95y6OpvlSJl+uydJ8yXd5/OMvu7/q9tt7L1OjVp9ViZxIzZ/81nt+JFYri6AFRqfM9l6+MH+LiqouMTN8eYYvJ3KlzrMDzoFwpnBrhdYbGLO5BsrlW0tUVLWLSeRKiVzJM3jV6hhI8aV0vrxys3kGB4YjDW9rJpNpuE8qrYmZzpWiqfkTnGcskUvly4p2rP3rzy02cp5ryXyb7Rw/f7OxbQ0Gg411SKVBMdO50tmB8Gn/FTU47j9g1P384R/f+/ChI23knM4LYc/FEKHicrkcCoW8Xi/HcRzHeb3eUChULpcJRSiRd4OYqbnSCc4TTRZS+Vtkaz1w8Be//t2651954tmNP33g0SRfJmSezNw8zrpuff89ttZ4PO7z+QKBwKVLl0ZGRgKBwOzsrMVicblcExMTcm2lRN4NYoaupb463Z/ky2Tbf8B432/Wrd+w7cWtf3ryxc3HTloVi3Q6BiamZ9Eq4/G42+1eXFzM5XKhUMhisZjN5q6uLrPZzLIsy7LxeBzbVhyRnJ7RG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