: This article mainly introduces how php converts the number 1-1 million to Chinese characters, for example, 150 to one hundred and fifty. if you are interested in PHP tutorials, refer to it. Directly mount the instance
It has been written to hundreds of billions.
/**
* @ Author ja Song
* Replace 1-1 million numbers with Chinese characters, for example, 123-> one hundred and twenty-three
* @ Param [num] $ num [number]
* @ Return [string] [string]
*/
Function numToWord ($ num)
{
$ ChiNum = array ('0', '1', '2', '3', '4', '5', '6', '7 ', '8', '9 ');
$ ChiUni = array ('', '10', '100', '100', '100', '100', '100', '100 ', 'kil ');
$ ChiStr = '';
$ Num_str = (string) $ num;
$ Count = strlen ($ num_str );
$ Last_flag = true; // whether the previous one is 0
$ Zero_flag = true; // whether the first flag is used
$ Temp_num = null; // temporary number
$ ChiStr = ''; // splicing result
If ($ count = 2) {// double digits
$ Temp_num = $ num_str [0];
$ ChiStr = $ temp_num = 1? $ ChiUni [1]: $ chiNum [$ temp_num]. $ chiUni [1];
$ Temp_num = $ num_str [1];
$ ChiStr. = $ temp_num = 0? '': $ ChiNum [$ temp_num];
} Else if ($ count> 2 ){
$ Index = 0;
For ($ I = $ count-1; $ I> = 0; $ I --){
$ Temp_num = $ num_str [$ I];
If ($ temp_num = 0 ){
If (! $ Zero_flag &&! $ Last_flag ){
$ ChiStr = $ chiNum [$ temp_num]. $ chiStr;
$ Last_flag = true;
}
} Else {
$ ChiStr = $ chiNum [$ temp_num]. $ chiUni [$ index % 9]. $ chiStr;
$ Zero_flag = false;
$ Last_flag = false;
}
$ Index ++;
}
} Else {
$ ChiStr = $ chiNum [$ num_str [0];
}
Return $ chiStr;
}
$ Num = 150;
Echo numToWord ($ num );
The above section describes how to change the number from 1-1 million to Chinese characters in php, for example, 150 to one hundred and fifty, including some content, and hope to help friends who are interested in PHP tutorials.