A function used to convert Arabic numerals to Chinese numerals. after reading a function for converting Arabic numerals to Chinese numerals, I recently wrote a function called "Arabic numerals to Chinese numerals ". Only one similar one is found in the search for the essence area. I feel that my algorithm is good, so I posted it and shared it. if I want to use it for the amount conversion, do I have to modify the processing of the decimal part? Phpfu "> <LINKhref =" http://www.php100.com
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.
I felt that my algorithm was good, so I posted it and shared it. if you want to convert the amount, you need to modify the processing of the decimal part.
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 $ 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 ");
?>