Last active
December 15, 2015 17:16
-
-
Save devxoul/e4b04a8a4c831f39f9d8 to your computer and use it in GitHub Desktop.
Phone number formatter for Korean.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function phone($str) { | |
$AREA_CODES = array("010", "02", "011", "031", "012", "032", "033", "041", | |
"015", "042", "016", "043", "017", "044", "018", "051", | |
"019", "052", "053", "054", "055", "061", "062", "063", | |
"064"); | |
// 하이픈 모두 제거 | |
$flattened = str_replace("-", "", $str); | |
foreach ($AREA_CODES as $code) { | |
if (strpos($flattened, $code) !== 0) { | |
continue; | |
} | |
$else = substr($flattened, strlen($code)); | |
$middle = substr($else, 0, strlen($else) / 2); | |
$last = substr($else, strlen($else) / 2); | |
$numbers = array($code, $middle, $last); | |
return join($numbers, "-"); | |
} | |
return $str; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment