Created
May 29, 2017 10:31
-
-
Save khal3d/29786061050c64918bc397a82e7d04fd to your computer and use it in GitHub Desktop.
Fix and convert phone numbers
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 | |
$number = '+2pop0۱00193086۵'; | |
function fixPhoneNumbers($number) | |
{ | |
// Remove all non numerals characters | |
$number = preg_replace("/[^0-9\x{0660}-\x{0669}\x{06F0}-\x{06F9}\+]/u", '', $number); | |
// Convert indic to Arabic numerals | |
$persian_indic = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']; | |
$arabic_indic = ['٩', '٨', '٧', '٦', '٥', '٤', '٣', '٢', '١','٠']; | |
$num_list = range(0, 9); | |
$number = str_replace($persian_indic, $num_list, $number); | |
$number = str_replace($arabic_indic, $num_list, $number); | |
return $number; | |
} | |
var_dump(fixPhoneNumbers($number)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment