Server Side/PHP
숫자를 한글로
Dev. Tool
2023. 12. 1. 22:55
function number2hangul($number){
$num = array('', '일', '이', '삼', '사', '오', '육', '칠', '팔', '구');
$unit4 = array('', '만', '억', '조', '경');
$unit1 = array('', '십', '백', '천');
$res = array();
$number = str_replace(',','',$number);
$split4 = str_split(strrev((string)$number),4);
for($i=0;$i<count($split4);$i++){
$temp = array();
$split1 = str_split((string)$split4[$i], 1);
for($j=0;$j<count($split1);$j++){
$u = (int)$split1[$j];
if($u > 0) $temp[] = $num[$u].$unit1[$j];
}
if(count($temp) > 0) $res[] = implode('', array_reverse($temp)).$unit4[$i];
}
return implode('', array_reverse($res));
}
echo number2hangul("46701");