Last active
November 9, 2015 08:40
-
-
Save maryleloisa/2b85c09e249f933a425c to your computer and use it in GitHub Desktop.
Mobile Number Formatting
This file contains hidden or 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 | |
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