Created
April 19, 2014 06:27
-
-
Save darrylhein/11075916 to your computer and use it in GitHub Desktop.
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
// attempt to find the extension | |
$phone_ext_parts = explode('x', $_value); | |
if (isset($phone_ext_parts[1])) { | |
$phone_ext = preg_replace("/\D/", "", $phone_ext_parts[1]); | |
$phone_part_1 = preg_replace("/\D/", "-", $phone_ext_parts[0]); | |
} else { | |
$phone_ext = ''; | |
$phone_part_1 = preg_replace("/\D/", "-", $_value); | |
} | |
// replace all the duplicate dashes with a single and remove any trailing dashes | |
$phone_part_1 = trim(str_replace('--', '-', $phone_part_1), '-'); | |
$phone_parts = explode('-', $phone_part_1); | |
$phone_part_count = count($phone_parts); | |
// we only have 345-3234 | |
if ($phone_part_count == 2) { | |
$data[$row_num][$field] = '--' . $phone_part_1 . '-' . $phone_ext; | |
// we have 323-434-5456 | |
} else if ($phone_part_count == 3) { | |
$data[$row_num][$field] = '-' . $phone_part_1 . '-' . $phone_ext; | |
// we have 1-455-545-6567 | |
} else if ($phone_part_count == 4) { | |
$data[$row_num][$field] = $phone_part_1 . '-' . $phone_ext; | |
// we have 1-432-434-5455-455 | |
} else if ($phone_part_count == 5) { | |
$data[$row_num][$field] = $phone_part_1; // already has the extension in it | |
} else { | |
$errors[$row_num][] = 'The phone number in ' . $column_names[$field] . ' can\'t be broken into the different parts. The value is: "' . $value . '".'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment