PHP code example of codelibrary / world

1. Go to this page and download the library: Download codelibrary/world 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/ */

    

codelibrary / world example snippets


use CodeLibrary\World\CountryFinder;

// optional params
$extraCountryData = [
    [
        'name' => ['official' => 'Hellenic Republic'], // already existing key
        'altSpellings' => ['hellenicccccccc'], // new custom values
    ],
    [
        'name' => ['official' => 'Kingdom of Spain'],
        'altSpellings' => ['The Kingdom of Spain'],
    ],
];

$finder = new CountryFinder($extraCountryData);

$finder->name('invalid country name here'); // throw 'InvalidCountryNameException'

$country1 = $finder->name('Hellenicccccccc');
$country2 = $finder->name('the kingdom of spain');

$country2->hasName('spain'); // (bool) true
$country2->hasName('spain, the kindom of'); // (bool) false
echo $country2->name('fra'); // Royaume d'Espagne
echo $country2->nameCommon('fra'); // Espagne