Convert lowercase numbers to uppercase Chinese, which is convenient for financial reconciliation

 
 

/**
 *lowercase to uppercase Chinese
 */
 function cny ( $ns )
 {
 static $cnums = array ( "zero" , "one" , "two" , "three" , " four" , "wu " , "lu" , " 7" , "8 " , "9" ) ,
 $cnyunits = array ( "circle" , "angle" , "minute" ) ,
$grees = array("拾", "佰"            , "仟", "万", "拾", "佰", "仟", "亿");
list($ns1, $ns2) = explode(".", $ns, 2);
$ns2 = array_filter(array($ns2[1], $ns2[0]));
$ret = array_merge($ns2, array(implode("", $this->_cny_map_unit            (str_split($ns1), $grees)), ""));
$ret = implode("", array_reverse($this->_cny_map_unit($ret, $cnyunits)));
return str_replace(array_keys($cnums), $cnums, $ret);
}
/**
 * @param $list
 * @param $units
 * @return array
 */
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 ;
 }
 function test () {
 ECHO $ ​​THIS -> CNY ( ' 12345.6 ' ) ;
 //print 壹 万 仟 叁 肆 肆 陆 陆 角
}                        

        

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324684834&siteId=291194637