function toChineseNumber($money){ $money = round($money * 100, 0); $cnynums = array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"); $cnygrees = array("分", "角", "圆", "拾","佰","仟","万","拾","佰","仟","亿"); $reverMoney = strrev(strval($money)); $len = strlen($reverMoney); $return = ''; for($i=0; $i<$len; $i++) { if($reverMoney[$i] != 0) { $return .= $cnygrees[$i] . $cnynums[$reverMoney[$i]]; } elseif($i == 2 && $len == 3) { $return .= $cnygrees[$i] . $cnynums[0]; } elseif($i == 6) { $return .= $cnygrees[$i]; } } $return = str_rev_gb($return); return $return; }
需要下面反转中英字符函数
// 反转中英文字符 function str_rev_gb($str) { if(!is_string($str)||!mb_check_encoding($str,'UTF-8')){ return false; } $len = mb_strlen($str,'UTF-8'); $arr = []; for($i=0; $i<$len; $i++) { $arr[] = mb_substr($str, $i, 1, 'UTF-8'); } krsort($arr); $res = join($arr, ''); return $res; }
单位到亿