phpuef/country

v1.0.1 2025-05-18 17:00 UTC

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.

Static Badge

Packagist Downloads GitHub stars PHPStan Tests codecov

Versions

Stable Version GitHub Release GitHub Release

Also available in other languages

Go Implementation PHP Implementation

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

JanGalek actions-user

Join our Discord Community! 🎉

Discord

Click above to join our community on Discord!