PHP人民币小写数字转大写
2365
PHP在做财务数据相关业务的时候,经常会用到人民币金额转成大写的问题,站长图库找了一下,收集到这段代码,非常方便,有喜欢的收藏一下。
<?php $data = $_GET['data']; function china_cny($ns) { static $cnums = array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"), $cnyunits = array("圆", "角", "分","厘","毫"), $grees = array("拾", "佰", "仟", "万", "拾", "佰", "仟", "亿"); list($ns1, $ns2) = explode(".", $ns, 4); $ns2 = array_filter(array($ns2[3],$ns2[2],$ns2[1], $ns2[0])); //$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 $data."元</br>"; echo china_cny($data); ?>
演示:
本文网址:https://www.zztuku.com/index.php/detail-12579.html
站长图库 - PHP人民币小写数字转大写
申明:如有侵犯,请 联系我们 删除。
您还没有登录,请 登录 后发表评论!
提示:请勿发布广告垃圾评论,否则封号处理!!