true, self::ANDORRA => true, self::ANGOLA => true, self::ARGENTINA => true, self::ARMENIA => true, self::ARUBA => true, self::AUSTRALIA => true, self::AUSTRIA => true, self::AZERBAIJAN => true, self::BAHRAIN => true, self::BANGLADESH => true, self::BELARUS => true, self::BELGIUM => true, self::BELIZE => true, self::BENIN => true, self::BHUTAN => true, self::BOLIVIA => true, self::BOSNIA_HERZEGOVINA => true, self::BOTSWANA => true, self::BRAZIL => true, self::BRUNEI => true, self::BULGARIA => true, self::BURKINA_FASO => true, self::BURUNDI => true, self::CAMBODIA => true, self::CAMEROON => true, self::CAPE_VERDE_ISLANDS => true, self::CENTRAL_AFRICAN_REPUBLIC => true, self::CHILE => true, self::CHINA => true, self::COLOMBIA => true, self::COMOROS_AND_MAYOTTE => true, self::CONGO => true, self::COOK_ISLANDS => true, self::COSTA_RICA => true, self::CROATIA => true, self::CUBA => true, self::CYPRUS => true, self::CZECH_REPUBLIC => true, self::DENMARK => true, self::DJIBOUTI => true, self::ECUADOR => true, self::EGYPT => true, self::EL_SALVADOR => true, self::EQUATORIAL_GUINEA => true, self::ERITREA => true, self::ESTONIA => true, self::ETHIOPIA => true, self::FALKLAND_ISLANDS => true, self::FAROE_ISLANDS => true, self::FIJI => true, self::FINLAND => true, self::FRANCE => true, self::FRENCH_GUIANA => true, self::FRENCH_POLYNESIA => true, self::GABON => true, self::GAMBIA => true, self::GEORGIA => true, self::GERMANY => true, self::GHANA => true, self::GIBRALTAR => true, self::GREECE => true, self::GREENLAND => true, self::GUADELOUPE => true, self::GUAM => true, self::GUATEMALA => true, self::GUINEA => true, self::GUINEA_BISSAU => true, self::GUYANA => true, self::HAITI => true, self::HONDURAS => true, self::HONG_KONG => true, self::HUNGARY => true, self::ICELAND => true, self::INDIA => true, self::INDONESIA => true, self::IRAN => true, self::IRAQ => true, self::IRELAND => true, self::ISRAEL => true, self::ITALY => true, self::JAPAN => true, self::JORDAN => true, self::KENYA => true, self::KIRIBATI => true, self::NORTH_KOREA => true, self::SOUTH_KOREA => true, self::KUWAIT => true, self::KYRGYZSTAN => true, self::LAOS => true, self::LATVIA => true, self::LEBANON => true, self::LESOTHO => true, self::LIBERIA => true, self::LIBYA => true, self::LIECHTENSTEIN => true, self::LITHUANIA => true, self::LUXEMBOURG => true, self::MACAO => true, self::MACEDONIA => true, self::MADAGASCAR => true, self::MALAWI => true, self::MALAYSIA => true, self::MALDIVES => true, self::MALI => true, self::MALTA => true, self::MARSHALL_ISLANDS => true, self::MARTINIQUE => true, self::MAURITANIA => true, self::MEXICO => true, self::MICRONESIA => true, self::MOLDOVA => true, self::MONACO => true, self::MONGOLIA => true, self::MOROCCO => true, self::MOZAMBIQUE => true, self::MYANMAR => true, self::NAMIBIA => true, self::NAURU => true, self::NEPAL => true, self::NETHERLANDS => true, self::NEW_CALEDONIA => true, self::NEW_ZEALAND => true, self::NICARAGUA => true, self::NIGER => true, self::NIGERIA => true, self::NIUE => true, self::NORFOLK_ISLANDS => true, self::NORTHERN_MARIANA_ISLANDS => true, self::NORWAY => true, self::OMAN => true, self::PALAU => true, self::PANAMA => true, self::PAPUA_NEW_GUINEA => true, self::PARAGUAY => true, self::PERU => true, self::PHILIPPINES => true, self::POLAND => true, self::PORTUGAL => true, self::QATAR => true, self::REUNION => true, self::ROMANIA => true, self::RUSSIA_KAZAKHSTAN_UZBEKISTAN_TURKMENISTAN_AND_TAJIKSTAN => true, self::RWANDA => true, self::SAN_MARINO => true, self::SAO_TOME_AND_PRINCIPE => true, self::SAUDI_ARABIA => true, self::SENEGAL => true, self::SERBIA => true, self::SEYCHELLES => true, self::SIERRA_LEONE => true, self::SINGAPORE => true, self::SLOVAK_REPUBLIC => true, self::SLOVENIA => true, self::SOLOMON_ISLANDS => true, self::SOMALIA => true, self::SOUTH_AFRICA => true, self::SPAIN => true, self::SRI_LANKA => true, self::ST_HELENA => true, self::SUDAN => true, self::SURINAME => true, self::SWAZILAND => true, self::SWEDEN => true, self::SWITZERLAND => true, self::SYRIA => true, self::TAIWAN => true, self::THAILAND => true, self::TOGO => true, self::TONGA => true, self::TUNISIA => true, self::TURKEY => true, self::TUVALU => true, self::UGANDA => true, self::UKRAINE => true, self::UNITED_ARAB_EMIRATES => true, self::UNITED_KINGDOM => true, self::URUGUAY => true, self::NORTH_AMERICA => true, self::VANUATU => true, self::VENEZUELA => true, self::VIETNAM => true, self::WALLIS_AND_FUTUNA => true, self::YEMEN => true, self::ZAMBIA => true, self::ZANZIBAR => true, self::ZIMBABWE => true, ]; public static function fromPhoneNumber(string $number): ?string { $digits = str_replace(['+', ' ', '(', ')', '-'], '', $number); // Remove international call prefix, usually `00` or `011` // https://en.wikipedia.org/wiki/List_of_international_call_prefixes $digits = preg_replace('/^00|^011/', '', $digits); // Prefixes can be 3, 2, or 1 digits long // Attempt to match the longest first foreach ([3, 2, 1] as $length) { $code = substr($digits, 0, $length); if (isset(self::CODES[$code])) { return $code; } } return null; } }