PHP Classes
elePHPant
Icontem

Countries Info: Retrieve country information from MySQL database

Recommend this page to a friend!
  Info   View files Documentation   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (3)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-07-25 (25 days ago) RSS 2.0 feedNot enough user ratingsTotal: 264 This week: 3All time: 7,406 This week: 203Up
Version License PHP version Categories
countries-info 1.0.5Custom (specified...5Localization, PHP 5, Geography
Description Author

This class can retrieve country information from MySQL database.

It can query a MySQL database to retrieve several details of information about a country like: code, flag, name, latitude, longitude, elevation, continent, locale, IDD dial code, currency code, total population, total area.

The country name can be retrieved in different languages like arabic, czech, danish, german, english, spanish, french, hebrew, italian, japanese, ducth, portuguese, russian, chinese, etc..

Innovation Award
PHP Programming Innovation award nominee
May 2017
Number 2
Many applications need to know the names of the countries to show them to their users in their own native language.

This package provides a solution to quickly lookup the names of each country in many different languages by querying a MySQL database.

Manuel Lemos
  Performance   Level  
Name: Peter Kahl <contact>
Classes: 30 packages by
Country: Hong Kong Hong Kong
Age: ???
All time rank: 7064 in Hong Kong Hong Kong
Week rank: 21 Up1 in Hong Kong Hong Kong Up
Innovation award
Innovation award
Nominee: 17x

Details

Country Info (Multilingual)

Converts country code to full name in any of 16 languages and provides other useful information. Can be used to generate HTML code.

Available data: * country names in 16 languages and scripts * emoji flags * locale (language code) * corresponding continent code * latitude and longitude of each country's centroid * elevation (altitude) in metres * international calling code * total population * area in km≤ * currency code * Google Maps API place_id

Available languages: * Arabic (????) * Czech (?e?tina) * German (Deutsch) * Danish (dansk) * English * Spanish (espaŮol) * French (franÁais) * Hebrew (???????) * Italian (italiano) * Japanese (???) * Dutch (Nederlands) * Portuguese (portuguÍs) * Russian (???????) * Slovak (sloven?ina) * Chinese simplified (????) * Chinese traditional (????)

Usage Examples

Generate HTML for select (drop-down list) of country names:

use peterkahl\Countries\Countries;

$link = mysqli_connect($DB_HOSTNAME, $DB_USERNAME, $DB_PASSWORD, $DB_DBNAME);

mysqli_set_charset($link, "utf8mb4");

$countryObj = new Countries;
$countryObj->dbresource = $link;
$array = $countryObj->getAllCodesNames('zh-tw'); # Chinese traditional

echo '<select>';
foreach ($array as $val) {
  echo '<option value="'.$val['code'].'">'.$val['name'].'</option>';
}
echo '</select>';

Translate country name:

use peterkahl\Countries\Countries;

$link = mysqli_connect($DB_HOSTNAME, $DB_USERNAME, $DB_PASSWORD, $DB_DBNAME);

mysqli_set_charset($link, "utf8mb4");

$countryObj = new Countries;
$countryObj->dbresource = $link;

echo $countryObj->code2countryName('US', 'ru'); # ??????????? ?????

Get all information for a given country:

use peterkahl\Countries\Countries;

$link = mysqli_connect($DB_HOSTNAME, $DB_USERNAME, $DB_PASSWORD, $DB_DBNAME);

mysqli_set_charset($link, "utf8mb4");

$countryObj = new Countries;
$countryObj->dbresource = $link;

$array = $countryObj->getCountryInfo('VC');
var_dump($array);
/*
array(29) {
  ["code"]=>
  string(2) "VC"
  ["cur_code"]=>
  string(3) "XCD"
  ["flag"]=>
  string(8) "??"
  ["longname"]=>
  string(32) "Saint Vincent and the Grenadines"
  ["name_ar"]=>
  string(36) "???? ????? ????????"
  ["name_cs"]=>
  string(26) "Svatż Vincent a Grenadiny"
  ["name_da"]=>
  string(29) "Saint Vincent og Grenadinerne"
  ["name_de"]=>
  string(30) "St. Vincent und die Grenadinen"
  ["name_en"]=>
  string(32) "Saint Vincent and the Grenadines"
  ["name_es"]=>
  string(28) "San Vicente y las Granadinas"
  ["name_fr"]=>
  string(31) "Saint-Vincent-et-les Grenadines"
  ["name_he"]=>
  string(40) "??? ?????? ??????????"
  ["name_it"]=>
  string(26) "Saint Vincent e Grenadines"
  ["name_ja"]=>
  string(54) "??????????????????"
  ["name_nl"]=>
  string(30) "Saint Vincent en de Grenadines"
  ["name_pt"]=>
  string(25) "S„o Vicente e Granadinas"
  ["name_ru"]=>
  string(45) "????-??????? ? ?????????"
  ["name_sk"]=>
  string(28) "Svštż Vincent a GrenadŪny"
  ["name_zh-cn"]=>
  string(30) "??????????"
  ["name_zh-hk"]=>
  string(30) "??????????"
  ["latitude"]=>
  string(10) "13.2528179"
  ["longitude"]=>
  string(11) "-61.1970774"
  ["elevation"]=>
  string(7) "624.517"
  ["continent"]=>
  string(2) "NA"
  ["locale"]=>
  string(5) "en_VC"
  ["dialcode"]=>
  string(4) "1784"
  ["area"]=>
  string(3) "389"
  ["population"]=>
  string(6) "103000"
  ["place_id"]=>
  string(27) "ChIJuzU5nuKsQIwRsaHSjejT_TE"
}
*/
  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file countries.sql Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file Countries.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:264
This week:3
All time:7,406
This week:203Up
User Comments (1)