chibifr/country-converter

一个PHP包,可以将国家ISO转换为国家名称,反之亦然。

1.0.0 2015-11-15 20:48 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:20:34 UTC


README

一个PHP包,可以将国家ISO转换为国家名称,反之亦然。

安装

要安装此包,请确保您已安装composer。然后,将其添加到require中

composer require chibifr/country-converter

使用方法

现在您可以使用它非常容易!在用composer添加了包之后,开始使用它

无异常管理

<?php
// Require the composer's vendor autoload file
require './vendor/autoload.php';

use ChibiFR\CountryConverter\Converter;

// Create a new Converter object
$converter = new Converter();

// Get a country name from its ISO code
echo $converter->getCountryName('jp'); // will echo "Japan"

// Get a country ISO code from its name
echo $converter->getCountryCode('France'); // will echo "FR"

有异常管理

<?php
// Require the composer's vendor autoload file
require './vendor/autoload.php';

use ChibiFR\CountryConverter\Converter;

// Create a new Converter object
$converter = new Converter();

// Get a country name from its ISO code
try {
    echo $converter->getCountryName('jp'); // will echo "Japan"
} catch (InvalidCountryNameException $e) {
    die($e->getMessage());
}

// Get a country ISO code from its name
try {
    echo $converter->getCountryCode('France'); // will echo "FR"
} catch (InvalidCountryCodeException $e) {
    die($e->getMessage());
}