早上公交上总想这个问题,终于写出来了,不知道有错误没
1 $chinese = array("零","一","二","三","四","五","六","七","八","九");
2 $str = 140032002005;
3 $arr = array();
4
5 $num = floor(strlen($str)/4);
6 $ss = substr($str, 0, strlen($str)-$num*4);
7 $i = 0;
8 while($num>0){
9 $arr[] = substr($str, -4-$i*4,4);
10 $num--;
11 $i++;
12 }
13 if($ss != "") $arr[] = $ss;
14 $strr = array();
15 foreach ($arr as $k => $v) {
16 $strrr = "";
17 for ($j=strlen($v);$j>0;$j--) {
18 switch ($j) {
19 case 4:
20 $strrr .= $v[strlen($v)-$j] != 0 ? $chinese[$v[strlen($v)-$j]]."千" : $chinese[0];
21 break;
22 case 3:
23 $strrr .= $v[strlen($v)-$j] != 0 ? $chinese[$v[strlen($v)-$j]]."百" : ($v[strlen($v)-$j+1]==0 ? "" : $chinese[0]);
24 break;
25 case 2:
26 $strrr .= $v[strlen($v)-$j] != 0 ? $chinese[$v[strlen($v)-$j]]."十" : ($v[strlen($v)-$j+1]==0 ? "" : $chinese[0]);
27 break;
28 case 1:
29 $strrr .= $v[strlen($v)-$j] != 0 ? $chinese[$v[strlen($v)-$j]] : "";
30 break;
31 }
32 }
33 if($k%2 == 1) $strrr = $strrr."万";
34 if($k%2 == 0 && $k!=0) $strrr = $strrr."亿";
35 $strr[] = $strrr;
36 }
37 header("Content-type: text/html; charset=utf-8");//浏览器改不了编码了
38 krsort($strr);
39 var_dump(implode("", $strr));exit;
时间: 2024-10-20 21:02:53