Skip to content

Instantly share code, notes, and snippets.

@khal3d
Created May 29, 2017 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khal3d/29786061050c64918bc397a82e7d04fd to your computer and use it in GitHub Desktop.
Save khal3d/29786061050c64918bc397a82e7d04fd to your computer and use it in GitHub Desktop.
Fix and convert phone numbers
<?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