Php converts the number 1-1 million into Chinese characters, for example, 150 to one hundred and fifty, 1-1150
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 );