不负相思意
人民币金额数字转中文大写,无聊也用PHP写了一段相同功能的代码:Php代码 function cny($ns) { static $cnums=array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"), $cnyunits=array("圆","角","分"), $grees=array("拾","佰","仟","万","拾","佰","仟","亿"); list($ns1,$ns2)=explode(".",$ns,2); $ns2=array_filter(array($ns2[1],$ns2[0])); $ret=array_merge($ns2,array(implode("",_cny_map_unit(str_split($ns1),$grees)),"")); $ret=implode("",array_reverse(_cny_map_unit($ret,$cnyunits))); return str_replace(array_keys($cnums),$cnums,$ret); } function _cny_map_unit($list,$units) { $ul=count($units); $xs=array(); foreach (array_reverse($list) as $x) { $l=count($xs); if ($x!="0" || !($l%4)) $n=($x=='0'?'':$x).($units[($l-1)%$ul]); else $n=is_numeric($xs[0][0])?$x:''; array_unshift($xs,$n); } return $xs; }
鸿蒙传说
<?phpfunction exchange($number){$number=substr($number,0,2);$arr=array("零","一","二","三","四","五","六","七","八","九");if(strlen($number)==1){$result=$arr[$number];}else{if($number==10){$result="十";}else{if($number<20){$result="十";}else{$result=$arr[substr($number,0,1)]."十";}if(substr($number,1,1)!="0"){$result.=$arr[substr($number,1,1)]; }}}return $result."<br>";}echo exchange(1);echo exchange(11);echo exchange(21);?>这个可以转换两位。只是给楼主一个思路。授之以鱼不如授之以渔。