{"id":15984942,"url":"https://github.com/divineomega/php-countries","last_synced_at":"2025-03-18T01:30:26.769Z","repository":{"id":56969674,"uuid":"144559506","full_name":"DivineOmega/php-countries","owner":"DivineOmega","description":"🌍 PHP Countries is a library that provides an elegant syntax to country data.","archived":false,"fork":false,"pushed_at":"2021-07-28T08:42:10.000Z","size":126,"stargazers_count":8,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-02T01:50:11.466Z","etag":null,"topics":["countries","country-codes","geographic-data","geography","php","php-library"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DivineOmega.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-13T09:42:45.000Z","updated_at":"2023-12-06T16:21:23.000Z","dependencies_parsed_at":"2022-08-21T10:50:42.989Z","dependency_job_id":null,"html_url":"https://github.com/DivineOmega/php-countries","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DivineOmega%2Fphp-countries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DivineOmega%2Fphp-countries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DivineOmega%2Fphp-countries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DivineOmega%2Fphp-countries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DivineOmega","download_url":"https://codeload.github.com/DivineOmega/php-countries/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244139007,"owners_count":20404437,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["countries","country-codes","geographic-data","geography","php","php-library"],"created_at":"2024-10-08T02:11:33.187Z","updated_at":"2025-03-18T01:30:26.496Z","avatar_url":"https://github.com/DivineOmega.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🌍 PHP Countries\n\n[![Build Status](https://travis-ci.com/DivineOmega/php-countries.svg?branch=master)](https://travis-ci.com/DivineOmega/php-countries)\n[![Coverage Status](https://coveralls.io/repos/github/DivineOmega/php-countries/badge.svg?branch=master)](https://coveralls.io/github/DivineOmega/php-countries?branch=master)\n[![StyleCI](https://github.styleci.io/repos/144559506/shield?branch=master)](https://github.styleci.io/repos/144559506)\n[![Packagist](https://img.shields.io/packagist/dt/divineomega/php-countries.svg)](https://packagist.org/packages/divineomega/php-countries/stats)\n\nPHP Countries is a library that provides an elegant syntax to country data.\n\n## Installation\n\nYou can install PHP Countries via Composer, as follows.\n\n```\ncomposer require divineomega/php-countries\n```\n\n## Usage\n\nTo use PHP Countries, you must create a new `Countries` object.\n\n```php\nuse DivineOmega\\Countries\\Countries;\n\n$countries = new Countries;\n```\n\nYou can then call various methods on this object, to get country data.\n\n### Retrieving all countries\n\nYou can easily retrieve an array of all countries and iterate through them, as follows.\n\n```php\nforeach($countries-\u003eall() as $country) {\n    var_dump($country-\u003ename.' - '.$country-\u003eofficialName);\n}\n```\n\n### Retrieving country by name\n\nCountry details can be retrieved from the country's official or common name.\n\n```php\nvar_dump($countries-\u003egetByName('United Kingdom'));\n\n/* \nobject(DivineOmega\\Countries\\Country)#146 (17) {\n  [\"name\"]=\u003e\n  string(14) \"United Kingdom\"\n  [\"officialName\"]=\u003e\n  string(52) \"United Kingdom of Great Britain and Northern Ireland\"\n  [\"topLevelDomains\"]=\u003e\n  array(1) {\n    [0]=\u003e\n    string(3) \".uk\"\n  }\n  [\"isoCodeAlpha2\"]=\u003e\n  string(2) \"GB\"\n  [\"isoCodeAlpha3\"]=\u003e\n  string(3) \"GBR\"\n  [\"isoCodeNumeric\"]=\u003e\n  string(3) \"826\"\n  [\"languages\"]=\u003e\n  array(1) {\n    [0]=\u003e\n    string(7) \"English\"\n  }\n  [\"languageCodes\"]=\u003e\n  array(1) {\n    [0]=\u003e\n    string(3) \"eng\"\n  }\n  [\"currencyCodes\"]=\u003e\n  array(1) {\n    [0]=\u003e\n    string(3) \"GBP\"\n  }\n  [\"callingCodes\"]=\u003e\n  array(1) {\n    [0]=\u003e\n    string(2) \"44\"\n  }\n  [\"capital\"]=\u003e\n  string(6) \"London\"\n  [\"capitals\"]=\u003e\n  array(1) {\n    [0]=\u003e\n    string(6) \"London\"\n  }\n  [\"region\"]=\u003e\n  string(6) \"Europe\"\n  [\"subregion\"]=\u003e\n  string(15) \"Northern Europe\"\n  [\"latitude\"]=\u003e\n  int(54)\n  [\"longitude\"]=\u003e\n  int(-2)\n  [\"areaInKilometres\"]=\u003e\n  int(242900)\n  [\"nationality\"]=\u003e\n    string(7) \"British\"\n}\n*/\n```\n\n### Retrieving country by ISO 3166-1 code\n\nYou can get the data for a country by its ISO 3166-1 code. The 2 character, 3 character and numeric variations are all accepted.\n\n```php\nvar_dump($countries-\u003egetByIsoCode('USA'));\n\n/*\nobject(DivineOmega\\Countries\\Country)#4693 (16) {\n  [\"name\"]=\u003e\n  string(13) \"United States\"\n  [\"officialName\"]=\u003e\n  string(24) \"United States of America\"\n  // etc...\n}\n*/\n```\n\n### Retrieving country by language spoken\n\nProviding a language, will return an array of all countries in which that language is spoken. You can provide a language name or code.\n\n```php\nvar_dump($countries-\u003egetByLanguage('German'));\n\n/*\narray(5) {\n  [0]=\u003e\n  object(DivineOmega\\Countries\\Country)#4913 (16) {\n    [\"name\"]=\u003e\n    string(7) \"Belgium\"\n    [\"officialName\"]=\u003e\n    // etc...\n  }\n  [1]=\u003e\n  object(DivineOmega\\Countries\\Country)#4883 (16) {\n    [\"name\"]=\u003e\n    string(7) \"Germany\"\n    [\"officialName\"]=\u003e\n    string(27) \"Federal Republic of Germany\"\n    // etc...\n  }\n  [2]=\u003e\n  object(DivineOmega\\Countries\\Country)#4826 (16) {\n    [\"name\"]=\u003e\n    string(13) \"Liechtenstein\"\n    [\"officialName\"]=\u003e\n    string(29) \"Principality of Liechtenstein\"\n    // etc...\n  }\n  [3]=\u003e\n  object(DivineOmega\\Countries\\Country)#4808 (16) {\n    [\"name\"]=\u003e\n    string(10) \"Luxembourg\"\n    [\"officialName\"]=\u003e\n    string(25) \"Grand Duchy of Luxembourg\"\n    // etc...\n  }\n  [4]=\u003e\n  object(DivineOmega\\Countries\\Country)#4871 (16) {\n    [\"name\"]=\u003e\n    string(7) \"Namibia\"\n    [\"officialName\"]=\u003e\n    string(19) \"Republic of Namibia\"\n    // etc...\n  }\n}\n*/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdivineomega%2Fphp-countries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdivineomega%2Fphp-countries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdivineomega%2Fphp-countries/lists"}