Created
June 5, 2018 15:19
-
-
Save the7th/776430818ccffb1cdf0a0d959f7141cf to your computer and use it in GitHub Desktop.
Sanitize phone number for Malaysia
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
<?php | |
$prepare_phone_num = $phone_num; | |
$phone = $prepare_phone_num; | |
$phone = str_replace(["-", "–", " ", "+"], '', $phone); | |
if ("0" == substr($phone, 0, 1)) | |
{ | |
$phone = "6" . $phone; | |
} | |
if ("60" != substr($phone, 0, 2)) | |
{ | |
$phone = "60" . $phone; | |
} | |
return $phone; |
function phone_number_formatter($phone) {
$phone = str_replace(["-", "–", " ", "+"], '', $phone);
return substr($phone,0,1) == '0' ? "6".$phone : "60".$phone;
}
echo phone_number_formatter('+143334567');
mastaa tajulll
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
kalau macam ini ?