PHP code example of mikegarde / country-codes

1. Go to this page and download the library: Download mikegarde/country-codes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mikegarde / country-codes example snippets




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,
];
*/

$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';
}

$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';
}