以下代码是在网上找的,具体出处忘了
class numToUpper {
function del0 ($num ) {
return "" .intval($num );
}
function n2c ($x ) {
$arr_n = array ("零" ,"一" ,"二" ,"三" ,"四" ,"五" ,"六" ,"七" ,"八" ,"九" ,"十" );
return $arr_n [$x ];
}
function num_r ($abcd ) {
$arr = array ();
$str = "" ;
$flag = 0 ;
$flag_end = 1 ;
$size_r = strlen($abcd );
for ($i =0 ; $i <$size_r ; $i ++) {
$arr [$i ] = $abcd {$i };
}
$arrlen = count($arr );
for ($j =0 ; $j <$arrlen ; $j ++) {
$ch = $this ->n2c($arr [$arrlen -1 -$j ]);
if ($ch == "零" && $flag == 0 ){
$flag = 1 ;
$str = $ch .$str ;
continue ;
}elseif ($ch == "零" ){
continue ;
}
$flag = 0 ;
switch ($j ) {
case 0 : $str = $ch ; $flag_end = 0 ; break ;
case 1 : $str = $ch ."十" .$str ; break ;
case 2 : $str = $ch ."百" .$str ; break ;
case 3 : $str = $ch ."千" .$str ; break ;
}
}
if ($flag_end == 1 ){
mb_internal_encoding("UTF-8" );
$str = mb_substr($str , 0 , mb_strlen($str )-1 );
}
return $str ;
}
function num2ch ($num ) {
$num_real = $this ->del0($num );
$numlen = strlen($num_real );
$a = $b = $c = '' ;
if ($numlen >= 9 ){
$y =substr($num_real , -9 , 1 );
$wsbq = substr($num_real , -8 , 4 );
$gsbq = substr($num_real , -4 );
$a = $this ->num_r($this ->del0($gsbq ));
$b = $this ->num_r($this ->del0($wsbq ))."万" ;
$c = $this ->num_r($this ->del0($y ))."亿" ;
}elseif ($numlen <= 8 && $numlen >= 5 ){
$wsbq = substr($num_real , 0 , $numlen -4 );
$gsbq = substr($num_real , -4 );
$a = $this ->num_r($this ->del0($gsbq ));
$b = $this ->num_r($this ->del0($wsbq ))."万" ;
$c ="" ;
}elseif ($numlen <= 4 ){
$gsbq = substr( $num_real , -$numlen );
$a = $this ->num_r($this ->del0($gsbq ));
$b ="" ;
$c ="" ;
}
$ch_num = $c .$b .$a ;
return $ch_num ;
}
}