Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn the code for converting Chinese characters to numbers released yesterday. At the request of netizens, write another inversion algorithm, no problem was found after a simple test. Now I will share the Code. If you are interested, I can test the Code. If you have better algorithms, please share them with me, it's better to use original code!
Test2 ();
/**
* Method test
*/
Function test2 (){
Echo '2014. 22 => '. IntToCn (333030 ).' '; // 333,030
Echo '2014 => '. IntToCn (1111 ).' '; // One thousand one hundred and eleven
Echo '2014 => '. IntToCn (101010101 ).' '; // 0.1 billion 1,010,101
}
/**
* Convert numbers to Chinese Characters
* @ Param Int $ num the number to be parsed
* @ Param String $ string Initial Value
* @ Return String
* @ Author Anyon Zou
* @ Date
*/
Function IntToCn ($ num, $ string = array ()){
If (! Is_numeric ($ num )){
Return $ num;
}
$ Splits = array ('000000' => '000000', '000000' => '000000 ');
$ Chars = array ('000000' => '000000', '000000' => 'kil', '000000' => '100 ', '10' => '10', '1' => '', '0' => '0 ');
$ Ints = array ('0', '1', '2', '3', '4', '5', '6', '7 ', '8', '9', '10 ');
/*
* Split integers and Decimals
*/
$ Nums = explode ('.', "{$ num }");
$ Num = $ nums [0];
// Process Decimals
$ Dou = array ();
If (! Empty ($ nums [1]) {
Foreach (str_split ("{$ nums [1]}") as $ n ){
If (is_numeric ($ n )){
$ Dou [] = $ ints [intval ($ n)];
}
}
}
Unset ($ nums );
Foreach ($ splits as $ step => $ split ){
$ Floor = $ step> 0? Floor ($ num/intval ($ step): '0 ';
If ($ floor> 0 ){
$ String [] = IntToCn ($ floor). $ split;
$ Num = fmod ($ num, $ step );
}
}
$ String2 = array ();
Foreach ($ chars as $ step => $ char ){
$ Floor = $ step> 0? Floor ($ num/intval ($ step): '0 ';
If ($ floor> 0 ){
$ String [] = $ string2 [] = $ ints [$ floor]. $ char;
$ Num = fmod ($ num, $ step );
} Else if (count ($ string2)> 0 | (count ($ string)> 0 & $ step! = '000000') & $ string2 [count ($ string)-1]! = $ Ints [0] & $ num> 0 ){
$ String [] = $ ints [0];
}
}
If (! Empty ($ dou )){
$ String = array_merge ($ string, array ('point'), $ dou );
}
Return join ('', $ string );
}
Test Results
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB