Home  >  Article  >  php教程  >  php 根据啊拉伯数字转变成大写中文数字

php 根据啊拉伯数字转变成大写中文数字

WBOY
WBOYOriginal
2016-05-25 16:42:232819browse

根据用户输入的数字判断再转换成想要的大写数字,如果我们先把大小写存在一个数组,再判断进行转换就OK了,PHP实例代码如下:

<?php
$data = $_POST[&#39;rmb&#39;]; 
if (!ereg("^[0-9.]",$data) ) die(&#39;请输入数值!&#39;); 
 
$arr = array(&#39;零&#39;,&#39;壹&#39;,&#39;贰&#39;,&#39;叁&#39;,&#39;肆&#39;,&#39;伍&#39;,&#39;陆&#39;,&#39;柒&#39;,&#39;捌&#39;,&#39;玖&#39;); 
$arr2 = array(0=>&#39;&#39;,1=>&#39;十&#39;,2=>&#39;百&#39;,3=>&#39;千&#39;,4=>&#39;万&#39;,5=>&#39;十&#39;,6=>&#39;百&#39;,7=>&#39;千&#39;,8=>&#39;亿&#39;,9=>&#39;十&#39;,10=>&#39;百&#39;,11=>&#39;千&#39;); 
 
$len1 = strlen($int);//判断位数 
$arrlen = array(); 
for($i=1;$i<=$len1;$i++){ 
$sublen = substr($int, $i-1,1);   
$arra[&#39;value&#39;] = $sublen; 
$arra[&#39;len&#39;] = $len1 - $i+1; 
array_push($arrlen, $arra); 
} 
 
for($j=0;$j<=$len1;$j++){ 
$va = $arrlen[$j][&#39;value&#39;];//RMB 数值 
$valen = $arrlen[$j][&#39;len&#39;];//长度 确定单位 
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>


本文链接:

收藏随意^^请保留教程地址.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn