Directly go to the example
Written over 100 billion.
/**
* @author jaSON
* Change the number 1-100 million into Chinese characters, such as: 123->one hundred and twenty-three
* @param [num] $num [number]
* @return [string] [string]
*/
function numToWord($num)
{
$chiNum = array('zero', 'one', 'two', 'three', 'four ', 'five', 'six', 'seven', 'eight', 'nine');
$chiUni = array('','ten', 'hundred', 'thousand', 'ten thousand', 'Billion', 'Ten', 'Hundred', 'Thousand');
$chiStr = '';
$num_str = (string)$num;
$count = strlen($num_str);
$last_flag = true; //Whether the previous one is 0
$zero_flag = true; //Whether the first one is
$temp_num = null; / /Temporary number
$chiStr = '';//Splicing result
if ($count == 2) {//Two 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);