금액(문자) -> 숫자로 변환 함수
/* ----- 신규 함수 시작(문자|금액 to 숫자) ----- */
function trance_cut_all($string)
{
$out = 0;
$units = array('조'=> 1000000000000, '억' => 100000000, '만' => 10000);
$trance_num = array('일' => 1, '이' => 2, '삼' => 3, '사' => 4, '오' => 5, '육' => 6, '칠' => 7, '팔' => 8, '구' => 9);
$string = str_replace(",","", trim($string));
$string = str_replace(".","", $string);
$string = str_replace("각호각","", $string);
$string = str_replace("보증금","", $string);
$string = str_replace("전세","", $string);
$string = str_replace("매월","", $string);
$string = str_replace("월","", $string);
$string = str_replace("금","", $string);
$string = str_replace("각","", $string);
$string = str_replace(" ","", $string);
$string .= 'x';
foreach($units as $key => $value)
{
$cut_string = preg_replace('/'.$key.'.+/', $value, $string);
if(preg_match('/'.$key.'/', $string))
{
$chk = preg_replace('/'.$key.'.+/', '', $string);
$string = preg_replace('/.+'.$key.'/', '', $string);
$out += $units[$key]*trance_cut($chk);
}
}
$string = preg_replace('/x/', '', $string);
$out += $string? trance_cut($string) : 0;
return $out;
}
function trance_cut($in)
{
$out = 0;
$in .= 'x';
$units = array('천','백','십');
$units_value = array(1000,100,10);
$trance_num = array('일' => 1, '이' => 2, '삼' => 3, '사' => 4, '오' => 5, '육' => 6, '칠' => 7, '팔' => 8, '구' => 9, '천' => 1, '백' => 1, '십' => 1);
foreach($units as $key => $value)
{
$cut_string = preg_replace('/'.$value.'.+/', $value, $in);
if(preg_match('/'.$value.'/', $in))
{
$chk = preg_replace('/'.$value.'.+/', '', $in);
// if($chk == "") $chk = '일';
$in = preg_replace('/.+'.$value.'/', '', $in);
$out += $units_value[$key]*$trance_num[$chk];
}
}
$in = preg_replace('/x/', '', $in);
$out += $in? $trance_num[$in] : 0;
return $out;
}
/* ----- 신규 함수 끝(문자|금액 to 숫자) ----- */