根据用户输入的数字判断再转换成想要的大写数字,如果我们先把大小写存在一个数组,再判断进行转换就OK了,PHP实例代码如下:
- $data = $_POST['rmb'];
- if (!ereg("^[0-9.]",$data) ) die('请输入数值!');
-
- $arr = array('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
- $arr2 = array(0=>'',1=>'十',2=>'百',3=>'千',4=>'万',5=>'十',6=>'百',7=>'千',8=>'亿',9=>'十',10=>'百',11=>'千');
-
- $len1 = strlen($int);
- $arrlen = array();
- for($i=1;$i<=$len1;$i++){
- $sublen = substr($int, $i-1,1);
- $arra['value'] = $sublen;
- $arra['len'] = $len1 - $i+1;
- array_push($arrlen, $arra);
- }
-
- for($j=0;$j<=$len1;$j++){
- $va = $arrlen[$j]['value'];
- $valen = $arrlen[$j]['len'];
- switch ($vc == $va)
- {
- case 0: echo $arr[0];break;case 1: echo $arr[1];break;
- case 2: echo $arr[2];break;case 3: echo $arr[3];break;
- case 4: echo $arr[4];break;case 5: echo $arr[5];break;
- case 6: echo $arr[6];break;case 7: echo $arr[7];break;
- case 8: echo $arr[8];break;case 9: echo $arr[9];break;
-
- }
-
- ?>
-
- <form id="form1" name="form1" method="post" action="">
- <input type="text" name="rmb" id="rmb" />
- <input type="submit" name="button" id="button" value="转换" />
- </form>
|