PHP code example of hamedhaghi / countries

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

    

hamedhaghi / countries example snippets




use Hamed\Countries\Factory\CountryRepositoryFactory;

// Initialize the client
$factory = new CountryRepositoryFactory();

// Enable caching for faster responses (optional)
$factory = $factory->isCachable()
                   ->setCacheTTL(3600); // Cache expiration time in seconds

// Initialize the repository
$repository = $factory->init();

// Query country data
$countries = $repository->getAll();
$countries = $repository->getByCapital('Berlin');
$countries = $repository->getByCode('DE');
$countries = $repository->getByCurrency('euro');
$countries = $repository->getByDemonym('German');
$countries = $repository->getByFullName('Germany');
$countries = $repository->getByLanguage('German');
$countries = $repository->getByName('Germany');
$countries = $repository->getByRegion('Europe');
$countries = $repository->getBySubregion('Western Europe');
$countries = $repository->getByTranslation('Germany');

// Clear the cache
$factory->clearCache();