On the internet to see a very interesting php RMB amount number to the Chinese capital function, the essence is the number converted into Chinese capital, tested a bit, very interesting, casually lose a number, you can print out its capital, novice friends try it, extrapolate, you can also write a lot of interesting PHP conversion functions.
Copy Code code as follows:
?
Function CNY ($NS) {
Static $cnums =array ("0", "one", "II", "three", "Restaurant", "WU", "Lu", "Qi", "ba", "Nine"),
$cnyunits =array ("Round", "horn", "cent"),
$grees =array ("Pick Up", "Bai", "Qian", "Million", "Pick Up", "Bai", "Qian", "billion");
List ($ns 1, $ns 2) =explode (".", $ns, 2);
$ns 2=array_filter (Array ($ns 2[1], $ns 2[0]));
$ret =array_merge ($ns 2,array (Implode ("", _cny_map_unit (Str_split ($ns 1), $grees));
$ret =implode ("", Array_reverse (_cny_map_unit ($ret, $cnyunits));
Return Str_replace (Array_keys ($cnums), $cnums, $ret);
}
Copy Code code as follows:
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;
}
?>
Use method: Directly pass the numeric parameter, the following example prints out the number of uppercase. Output: One million thousand one hundred to pick a circle
Copy Code code as follows:
<?php
Echo CNY (' 12121 ');
?>