libphonenumber\PhoneNumberUtil::normalize PHP Method

normalize() public static method

For ALPHA/VANITY numbers: Letters are converted to their numeric representation on a telephone keypad. The keypad used here is the one defined in ITU Recommendation E.161. This is only done if there are 3 or more letters in the number, to lessen the risk that such letters are typos. For other numbers: Wide-ascii digits are converted to normal ASCII (European) digits. Arabic-Indic numerals are converted to European numerals. Spurious alpha characters are stripped.
public static normalize ( string &$number ) : string
$number string a string of characters representing a phone number.
return string the normalized string version of the phone number.
    public static function normalize(&$number)
    {
        if (static::$ALPHA_PHONE_MAPPINGS === null) {
            static::initAlphaPhoneMappings();
        }
        $m = new Matcher(static::VALID_ALPHA_PHONE_PATTERN, $number);
        if ($m->matches()) {
            return static::normalizeHelper($number, static::$ALPHA_PHONE_MAPPINGS, true);
        } else {
            return static::normalizeDigitsOnly($number);
        }
    }

Usage Example

 public function testNormaliseOtherDigits()
 {
     $inputNumber = "2" . "5٥";
     $expectedOutput = "255";
     $this->assertEquals($expectedOutput, $this->phoneUtil->normalize($inputNumber), "Conversion did not correctly replace non-latin digits");
     // Eastern-Arabic digits.
     $inputNumber = "۵" . "2۰";
     $expectedOutput = "520";
     $this->assertEquals($expectedOutput, $this->phoneUtil->normalize($inputNumber), "Conversion did not correctly replace non-latin digits");
 }
PhoneNumberUtil