MikeGarde/country-codes

ISO 3166-1 国家代码

0.6.1 2024-05-17 19:13 UTC

This package is auto-updated.

Last update: 2024-09-17 20:35:10 UTC


README

Packagist Packagist GitHub GitHub code size in bytes Libraries.io dependency status for GitHub repo codecov

国家代码与美国州

ISO 3166-1, 3166-2-US

安装

Packagist 上查找,并使用 Composer 进行安装。

composer require mikegarde/country-codes

使用

国家代码

include 'vendor/autoload.php';

use Countries\Countries;

$countries = new Countries();
$result    = $countries->getCountry('US');
$result    = $countries->getCountry('USA');
$result    = $countries->getCountry('UnitedStates');
$result    = $countries->getCountry('United States');
$result    = $countries->getCountry('United States of America');

/*
$result = [
    'name'    => 'United States',
    'iso2'    => 'US',
    'iso3'    => 'USA',
    'isoNum'  => '840',
    'fips'    => 'US',
    'capital' => 'Washington',
    'isEU'    => 0,
    'isUK'    => 0,
    'isUS'    => 0,
];
*/

用于您的UI

$countries = new Countries();
$results   = $countries->getAllCountries();

return json_encode($results);

美国领地

$countries = new Countries(true);
if ($countries->isUSTerritory('PR'))
{
    echo 'Yep, a US Territory';
}

为加拿大做些事情

if ($countries->validate('CA', $order['consignee']['countryCode']))
{
    echo 'Blame Canada';
}

美国州

当在48州以下地区发货时执行不同的操作

$stateTest = new US();

if ($stateTest->isCONUS($order['consignee']['state']))
{
    echo 'You can select USPS, UPS, or DHL';
}
else // OCONUS
{
   echo 'USPS is your only option for shipping to AK, HI, APO, or an FPO address';
}

本地开发注意事项

命令后面的数字表示PHP版本

task build-8.3
task setup-8.3
task test-8.3

或者您也可以运行 task test-all 来构建、设置并测试所有支持的PHP版本。