将int数字转为中文字符串

 1 function int_to_cnstr($intval) {
 2     $cnNum = array('零','一','二','三','四','五','六','七','八','九');
 3     $cnUnit = array('','十','百','千','万','亿');
 4     $reCnStr = '';
 5     $intval = intval($intval);
 6     if ($intval < 10 && $intval >= 0) {
 7         $reCnStr .= $cnNum[$intval];
 8     } elseif ($intval == 1000000000) {
 9         $reCnStr .= $cnNum[1].$cnUnit[5];
10     } elseif ($intval < 0 || $intval > 1000000000) {
11         $reCnStr .= '';
12     } else {
13         $str = strval($intval);
14         $len = strlen($str);
15         for ($i = 0; $i < $len; $i++) {
16             if (intval($str{$i}) != 0) {
17                 $reCnStr .= $cnNum[intval($str{$i})];
18                 $j = $len - 1 - $i;
19                 if ($j < 5) {
20                     $reCnStr .= $cnUnit[$j];
21                 } elseif ($j >=5 && $j <= 8) {
22                     $reCnStr .= $cnUnit[$j - 4];
23                 }
24             } else {
25                 if ($i > 0 && $str{$i} != $str{$i - 1}) $reCnStr .= $cnNum[0];
26             }
27         }
28     }
29     return $reCnStr;
30 }

 

posted @ 2018-03-17 21:50  zhaoxlchn  阅读(962)  评论(0编辑  收藏  举报