Recently, as a result of this need, I wrote a "Arabic numerals to Chinese numerals" function ". Only one similar one is found in the search for the essence area.
Feel myAlgorithmYes, so share it. If you want to convert the amount, you need to modify the processing of the decimal part.
<? PHP
Function ch_num ($ num, $ mode = true ){
$ Char = array ("zero", "one", "two", "three", "Si", "Wu", "Lu", "Jun ", "success", "fail ");
$ DW = array ("", "Pick", "audio", "audio", "", "audio", "audio", "MB ");
$ Dec = "point ";
$ Retval = "";
If ($ Mode)
Preg_match_all ("/^ 0 * (\ D *)\.? (\ D *)/", $ num, $ AR );
Else
Preg_match_all ("/(\ D *)\.? (\ D *)/", $ num, $ AR );
If ($ ar [2] [0]! = "")
$ Retval = $ dec. ch_num ($ ar [2] [0], false); // if there is a decimal number, first recursively process the decimal number
If ($ ar [1] [0]! = ""){
$ STR = strrev ($ ar [1] [0]);
For ($ I = 0; $ I <strlen ($ Str); $ I ++ ){
$ Out [$ I] = $ char [$ STR [$ I];
If ($ mode ){
$ Out [$ I]. = $ STR [$ I]! = "0 "? $ DW [$ I % 4]: "";
If ($ STR [$ I] + $ STR [$ I-1] = 0)
$ Out [$ I] = "";
If ($ I % 4 = 0)
$ Out [$ I]. = $ DW [4 + floor ($ I/4)];
}
}
$ Retval = join ("", array_reverse ($ out). $ retval;
}
Return $ retval;
}
// Echo ch_num ("12345006789001.123 ");
// Echo ch_num ("880079.1234 ");
Echo ch_num ("300045.0123 ");
?>