• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/phonenumber/parser.php
  • Класс: BitrixMainPhoneNumberParser
  • Вызов: Parser::parsePhoneNumberAndCountryPhoneCode
protected function parsePhoneNumberAndCountryPhoneCode($phoneNumber)
{
	$phoneNumber = $this->normalizePhoneNumber($phoneNumber);
	if(!$phoneNumber)
		return false;

	// If this is not an international phone number,
	// then don't extract country phone code.
	if ($phoneNumber[0] !== $this->plusChar)
	{
		return array(
			'countryCode' => '',
			'localNumber' => $phoneNumber
		);
	}

	// Strip the leading '+' sign
	$phoneNumber = mb_substr($phoneNumber, 1);

	// Fast abortion: country codes do not begin with a '0'
	if ($phoneNumber[0] === '0')
	{
		return false;
	}

	for ($i = static::MAX_LENGTH_COUNTRY_CODE; $i > 0; $i--)
	{
		$countryCode = mb_substr($phoneNumber, 0, $i);
		if(MetadataProvider::getInstance()->isValidCountryCode($countryCode))
		{
			return array(
				'countryCode' => $countryCode,
				'localNumber' => mb_substr($phoneNumber, $i)
			);
		}
	}
	return false;
}