php countries
v2.3.0
php countries 는 국가 데이터에 우아한 구문을 제공하는 라이브러리입니다.
다음과 같이 Composer를 통해 php countries 설치할 수 있습니다.
composer require divineomega/php-countries
php countries 사용하려면 새로운 Countries
객체를 생성해야 합니다.
use DivineOmega Countries Countries ;
$ countries = new Countries ;
그런 다음 이 개체에 대해 다양한 메서드를 호출하여 국가 데이터를 얻을 수 있습니다.
다음과 같이 모든 국가의 배열을 쉽게 검색하고 반복할 수 있습니다.
foreach ( $ countries -> all () as $ country ) {
var_dump ( $ country -> name . ' - ' . $ country -> officialName );
}
국가 세부정보는 해당 국가의 공식 이름이나 일반 이름에서 검색할 수 있습니다.
var_dump ( $ countries -> getByName ( ' United Kingdom ' ));
/*
object(DivineOmegaCountriesCountry)#146 (17) {
["name"]=>
string(14) "United Kingdom"
["officialName"]=>
string(52) "United Kingdom of Great Britain and Northern Ireland"
["topLevelDomains"]=>
array(1) {
[0]=>
string(3) ".uk"
}
["isoCodeAlpha2"]=>
string(2) "GB"
["isoCodeAlpha3"]=>
string(3) "GBR"
["isoCodeNumeric"]=>
string(3) "826"
["languages"]=>
array(1) {
[0]=>
string(7) "English"
}
["languageCodes"]=>
array(1) {
[0]=>
string(3) "eng"
}
["currencyCodes"]=>
array(1) {
[0]=>
string(3) "GBP"
}
["callingCodes"]=>
array(1) {
[0]=>
string(2) "44"
}
["capital"]=>
string(6) "London"
["capitals"]=>
array(1) {
[0]=>
string(6) "London"
}
["region"]=>
string(6) "Europe"
["subregion"]=>
string(15) "Northern Europe"
["latitude"]=>
int(54)
["longitude"]=>
int(-2)
["areaInKilometres"]=>
int(242900)
["nationality"]=>
string(7) "British"
}
*/
ISO 3166-1 코드로 국가에 대한 데이터를 얻을 수 있습니다. 2자, 3자 및 숫자 변형이 모두 허용됩니다.
var_dump ( $ countries -> getByIsoCode ( ' USA ' ));
/*
object(DivineOmegaCountriesCountry)#4693 (16) {
["name"]=>
string(13) "United States"
["officialName"]=>
string(24) "United States of America"
// etc...
}
*/
언어를 제공하면 해당 언어가 사용되는 모든 국가의 배열이 반환됩니다. 언어 이름이나 코드를 제공할 수 있습니다.
var_dump ( $ countries -> getByLanguage ( ' German ' ));
/*
array(5) {
[0]=>
object(DivineOmegaCountriesCountry)#4913 (16) {
["name"]=>
string(7) "Belgium"
["officialName"]=>
// etc...
}
[1]=>
object(DivineOmegaCountriesCountry)#4883 (16) {
["name"]=>
string(7) "Germany"
["officialName"]=>
string(27) "Federal Republic of Germany"
// etc...
}
[2]=>
object(DivineOmegaCountriesCountry)#4826 (16) {
["name"]=>
string(13) "Liechtenstein"
["officialName"]=>
string(29) "Principality of Liechtenstein"
// etc...
}
[3]=>
object(DivineOmegaCountriesCountry)#4808 (16) {
["name"]=>
string(10) "Luxembourg"
["officialName"]=>
string(25) "Grand Duchy of Luxembourg"
// etc...
}
[4]=>
object(DivineOmegaCountriesCountry)#4871 (16) {
["name"]=>
string(7) "Namibia"
["officialName"]=>
string(19) "Republic of Namibia"
// etc...
}
}
*/