phpuef / country
Requires (Dev)
- contributte/qa: ^0.3.2
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^12.1
- slevomat/coding-standard: ^8.18.0
- squizlabs/php_codesniffer: ^3.13
This package is auto-updated.
Last update: 2025-05-18 18:13:33 UTC
README
Country
This package provides functions to search for country information (ISO 3166-1) based on their country codes (Alpha-2, Alpha-3, Numeric) and names. It is designed for easy integration into applications that need to work with country codes or names.
Versions
Also available in other languages
Installation
composer require phpuef/country
Usage
Country
Class
Each country is represented by the Country
class, which contains the following fields:
name
: The country's name (in English).alpha2
: The two-letter country code (ISO 3166-1 alpha-2).alpha3
: The three-letter country code (ISO 3166-1 alpha-3).numeric
: The numeric country code (ISO 3166-1 numeric).
Functions
FindByAlpha2(string $alpha2): ?Country
This function searches for a country by its two-letter Alpha-2 code.
<?php use Phpuef\Country\Countries; class Example { public function findCZ() { $country = Countries::FindByAlpha2("CZ") if ($country !== null) { echo "Country Name: " + $country?->name; echo "Alpha-2 Code:: " + $country?->alpha2; } } }
FindByAlpha3(string $alpha3): ?Country
This function searches for a country by its three-letter Alpha-3 code.
<?php use Phpuef\Country\Countries; class Example { public function findCZ() { $country = Countries::FindByAlpha3("CZE") if ($country !== null) { echo "Country Name: " + $country?->name; echo "Alpha-3 Code:: " + $country?->alpha3; } } }
FindByName *Country
This function searches for a country by its name (english).
<?php use Phpuef\Country\Countries; class Example { public function findCZ() { $country = Countries::FindByName("Czechia") if ($country !== null) { echo "Country Name: " + $country?->name; echo "Alpha-2 Code:: " + $country?->alpha2; echo "Alpha-3 Code:: " + $country?->alpha3; } } }
Contributing
Read Contributing
Contributors
Join our Discord Community! 🎉
Click above to join our community on Discord!