首頁 >php教程 >php手册 >PHP实现人民币金额数字转中文大写

PHP实现人民币金额数字转中文大写

WBOY
WBOY原創
2016-06-06 19:57:041344瀏覽

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 PHP实现人民币金额数字转中文大写: ?php header("Content-Type:text/html;charset=utf-8"); error_reporting(2); function cny($ns) { static $cnums=array("零","壹","贰","叁","肆","伍"

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  PHP实现人民币金额数字转中文大写:

  

  header("Content-Type:text/html;charset=utf-8");

  error_reporting(2);

  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;

  }

  echo cny('15897');

  ?>

PHP实现人民币金额数字转中文大写

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn