hollodotme/iso-country-codes

代表 ICO-3166-1 国家代码的值对象集合

v1.0.0 2020-08-17 16:35 UTC

This package is not auto-updated.

Last update: 2024-09-12 05:13:11 UTC


README

Unit tests Static analysis

ISO-3166-1 国家代码

这是一个静态生成的 ISO-3166-1 国家代码值对象集合,包含以下表示形式

  • 英文简称
  • 法语简称
  • Alpha-2 代码
  • Alpha-3 代码
  • 数字代码

数据来源: https://www.iso.org/obp/ui/#search/code/

需求

  • PHP >= 7.4

安装

推荐使用 composer 安装此库。

composer require "hollodotme/iso-country-codes"

用法

从英文简称

<?php declare(strict_types=1);

use hollodotme\ISO\CountryCodes\CountryCode;

$countryCode = CountryCode::fromEnglishShortName( 'New Caledonia' );

echo $countryCode->getEnglishShortName(), "\n";
echo $countryCode->getFrenchShortName(), "\n";
echo $countryCode->getAlpha2Code(), "\n";
echo $countryCode->getAlpha3Code(), "\n";
echo $countryCode->getNumericCode();

打印

New Caledonia
Nouvelle-Calédonie (la)
NC
NCL
540

从法语简称

<?php declare(strict_types=1);

use hollodotme\ISO\CountryCodes\CountryCode;

$countryCode = CountryCode::fromFrenchShortName( 'Nouvelle-Calédonie (la)' );

echo $countryCode->getEnglishShortName(), "\n";
echo $countryCode->getFrenchShortName(), "\n";
echo $countryCode->getAlpha2Code(), "\n";
echo $countryCode->getAlpha3Code(), "\n";
echo $countryCode->getNumericCode();

打印

New Caledonia
Nouvelle-Calédonie (la)
NC
NCL
540

从 alpha-2 代码

<?php declare(strict_types=1);

use hollodotme\ISO\CountryCodes\CountryCode;

$countryCode = CountryCode::fromAlpha2Code( 'NC' );

echo $countryCode->getEnglishShortName(), "\n";
echo $countryCode->getFrenchShortName(), "\n";
echo $countryCode->getAlpha2Code(), "\n";
echo $countryCode->getAlpha3Code(), "\n";
echo $countryCode->getNumericCode();

打印

New Caledonia
Nouvelle-Calédonie (la)
NC
NCL
540

从 alpha-3 代码

<?php declare(strict_types=1);

use hollodotme\ISO\CountryCodes\CountryCode;

$countryCode = CountryCode::fromAlpha3Code( 'NCL' );

echo $countryCode->getEnglishShortName(), "\n";
echo $countryCode->getFrenchShortName(), "\n";
echo $countryCode->getAlpha2Code(), "\n";
echo $countryCode->getAlpha3Code(), "\n";
echo $countryCode->getNumericCode();

打印

New Caledonia
Nouvelle-Calédonie (la)
NC
NCL
540

从数字代码

<?php declare(strict_types=1);

use hollodotme\ISO\CountryCodes\CountryCode;

$countryCode = CountryCode::fromNumericCode( '540' );

echo $countryCode->getEnglishShortName(), "\n";
echo $countryCode->getFrenchShortName(), "\n";
echo $countryCode->getAlpha2Code(), "\n";
echo $countryCode->getAlpha3Code(), "\n";
echo $countryCode->getNumericCode();

打印

New Caledonia
Nouvelle-Calédonie (la)
NC
NCL
540