Skip to content

Instantly share code, notes, and snippets.

@cygeorgel
Created February 20, 2020 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cygeorgel/95e25e79b024a0397cc5d31416923a20 to your computer and use it in GitHub Desktop.
Save cygeorgel/95e25e79b024a0397cc5d31416923a20 to your computer and use it in GitHub Desktop.
Get list of phone numbers
function getContacts($data)
{
$contacts = [];
$data = str_replace(' ', '', $data);
$strings = explode(',', $data);
foreach ($strings as $string) {
if (strpos($string, '-') !== false) {
list($start, $end) = explode('-', $string);
if (strlen($end) == 2) {
$end = substr($start, 0, strlen($start) - 2) . $end;
}
$control = 0;
for ($number = $start; $number <= $end; $number++) {
array_push ($contacts, phoneNumberFormat($number));
$control++;
if ($control >= 100) {
break;
}
}
} else {
array_push ($contacts, phoneNumberFormat($string));
}
}
return implode(',', $contacts);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment