public static function amountInWords($num) {
if (!is_numeric($num) || empty($num))
return "";
$return = "";
$unit = array("分", "角", "圆", "整");
$dw = array("", "拾", "佰", "仟", "", "万", "亿", "兆");
$char = array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");
preg_match_all("/(\d*)\.?(\d*)/", $num, $ar);
if (intval($ar[2][0]) > 0) {
$return .= $ar[2][0][0] == 0 ? "" : $char[$ar[2][0][0]] . $unit[1];
if (isset($ar[2][0][1])) {
if (empty($return) && $ar[1][0] > 0)
$return = $char[0] . $char[$ar[2][0][1]] . $unit[0];
else
$return .= $char[$ar[2][0][1]] . $unit[0];
}
}else{
$return .= $unit[3];
}
if ($ar[1][0] != "") {
$str = strrev($ar[1][0]);
$len = strlen($str);
for ($i = 0; $i < $len; $i++) {
$out[$i] = $char[$str[$i]];
$out[$i] .= $str[$i] != "0"? $dw[$i%4] : "";
if ($str[$i] + $str[$i-1] == 0)
$out[$i] = "";
if ($i%4 == 0)
$out[$i] .= $dw[4+floor($i/4)];
if ($out[$i] == "零万")
$out[$i] = "万零";
}
$left = join("", array_reverse($out));
if (!empty($left))
$return = $left . $unit[2] . $return;
}
return $return;
}