Skip to content

Instantly share code, notes, and snippets.

@maryleloisa
Last active November 9, 2015 08:40
Show Gist options
  • Save maryleloisa/2b85c09e249f933a425c to your computer and use it in GitHub Desktop.
Save maryleloisa/2b85c09e249f933a425c to your computer and use it in GitHub Desktop.
Mobile Number Formatting
<?php
static function numonly($str)
{
return preg_replace('/\D/', '', $str);
}
static function trimMobile($mobile)
{
if (empty($mobile)) {
return false;
}
//Son 10 rakamından öncesini at
$mobile = substr(Utils::numonly($mobile), -10);
//İlk rakamı 5 ikinci rakamı (0|3|4|5) ve toplam 10 rakamdan oluşuyorsa numarayı ver
return substr($mobile, 0, 1) == 5 && in_array(substr($mobile, 1, 1), [0, 3, 4, 5]) && strlen($mobile) == 10 ? $mobile : false;
}
static function formatMobile($mobile)
{
sprintf("%s-%s-%s",
substr($mobile, 2, 3),
substr($mobile, 5, 3),
substr($mobile, 8));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment