Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@devxoul
Last active December 15, 2015 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devxoul/e4b04a8a4c831f39f9d8 to your computer and use it in GitHub Desktop.
Save devxoul/e4b04a8a4c831f39f9d8 to your computer and use it in GitHub Desktop.
Phone number formatter for Korean.
<?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