grnspc/countries

Countries 是一个简单且轻量级的包,用于灵活检索国家详细信息。只需轻轻一点,您就能获得250个国家的详细信息,包括名称、通称、首都、ISO代码、电话区号、地理数据、货币、国旗、表情符号以及其他属性。

v0.1.0 2023-02-27 15:34 UTC

This package is auto-updated.

Last update: 2024-09-27 19:04:12 UTC


README

GRNSPC Country 是一个简单且轻量级的包,用于灵活检索国家详细信息。您只需轻轻一点,就能获得250个国家的详细信息,包括名称、通称、首都、ISO代码、电话区号、地理数据、货币、国旗、表情符号以及其他属性。

Packagist License

用法

使用 composer require grnspc/countries 安装,然后直观使用

// Get single country
$egypt = country('eg');

// Get country name                                 // Get country native name
echo $egypt->getName();                             echo $egypt->getNativeName();

// Get country official name                        // Get country ISO 3166-1 alpha2 code
echo $egypt->getOfficialName();                     echo $egypt->getIsoAlpha2();

// Get country area                                 // Get country borders
echo $egypt->getArea();                             echo $egypt->getBorders();

// Get country currencies                           // Get country languages
echo $egypt->getCurrencies();                       echo $egypt->getLanguages();

// Get country emoji                                // Get country flag
echo $egypt->getEmoji();                            echo $egypt->getFlag();


// Get all countries                                // Get countries with where condition (continent: Oceania)
$countries = countries();                           $whereCountries = \Grnspc\Country\CountryLoader::where('geo.continent', ['OC' => 'Oceania']);

注意: 此包是框架无关的,因此它可以与任何PHP框架兼容,没有任何依赖,除了PHP版本本身 ^8.1。太棒了,不是吗? 😃

目录

高级用法

获取国家属性(自描述)

$egypt = country('eg');

// Egypt                                            // مصر
$egypt->getName();                                  $egypt->getNativeName();

// Arab Republic of Egypt                           // جمهورية مصر العربية
$egypt->getOfficialName();                          $egypt->getNativeOfficialName();

// Egyptian                                         // Cairo
$egypt->getDemonym();                               $egypt->getCapital();

// EG                                               // EGY
$egypt->getIsoAlpha2();                             $egypt->getIsoAlpha3();

// 818                                              // .eg
$egypt->getIsoNumeric();                            $egypt->getTld();

// [".eg",".مصر"]                                   // ["EG","Arab Republic of Egypt"]
$egypt->getTlds();                                  $egypt->getAltSpellings();

// Arabic                                           // {"ara":"Arabic"}
$egypt->getLanguage();                              $egypt->getLanguages();

// Africa                                           // true
$egypt->getContinent();                             $egypt->usesPostalCode();

// 27 00 N                                          // 30 00 E
$egypt->getLatitude();                              $egypt->getLongitude();

// 26.756103515625                                  // 29.86229705810547
$egypt->getLatitudeDesc();                          $egypt->getLongitudeDesc();

// 31.916667                                        // 36.333333
$egypt->getMaxLatitude();                           $egypt->getMaxLongitude();

// 20.383333                                        // 24.7
$egypt->getMinLatitude();                           $egypt->getMinLongitude();

// 1002450                                          // Africa
$egypt->getArea();                                  $egypt->getRegion();

// Northern Africa                                  // EMEA
$egypt->getSubregion();                             $egypt->getWorldRegion();

// 002                                              // 015
$egypt->getRegionCode();                            $egypt->getSubregionCode();

// false                                            // ["ISR","LBY","SDN"]
$egypt->isLandlocked();                             $egypt->getBorders();

// Yes                                              // 20
$egypt->isIndependent();                            $egypt->getCallingCode();

// ["20"]                                           // 0
$egypt->getCallingCodes();                          $egypt->getNationalPrefix();

// 9                                                // [9]
$egypt->getNationalNumberLength();                  $egypt->getNationalNumberLengths();

// 2                                                // [2]
$egypt->getNationalDestinationCodeLength();         $egypt->getnationaldestinationcodelengths();

// "00"                                             // {{recipient}}\n{{street}}\n{{postalcode}} {{city}}\n{{country}}
$egypt->getInternationalPrefix();                   $egypt->getAddressFormat();

// 357994                                           // H2
$egypt->getGeonameid();                             $egypt->getEdgar();

// EGY                                              // ua
$egypt->getItu();                                   $egypt->getMarc();

// EG                                               // ET
$egypt->getWmo();                                   $egypt->getDs();

// EGY                                              // EG
$egypt->getFifa();                                  $egypt->getFips();

// 40765                                            // EGY
$egypt->getGaul();                                  $egypt->getIoc();

// EGY                                              // 651
$egypt->getCowc();                                  $egypt->getCown();

// 59                                               // 469
$egypt->getFao();                                   $egypt->getImf();

// MAF                                              // null
$egypt->getAr5();                                   $egypt->isEuMember();

// null                                             // 🇪🇬
$egypt->getVatRates();                              $egypt->getEmoji();

// GeoJson data returned as string                  // SVG data returned as string
$egypt->getGeoJson();                               $egypt->getFlag();

// Divisions returned as array                      // {"official":"جمهورية مصر العربية","common":"مصر"}
$egypt->getDivisions();                             $egypt->getTranslation();

// ['Africa/Cairo']                                 // ['ar_EG']
$egypt->getTimezones();                             $egypt->getLocales();

// Other                                            // {"ara":{"official":"جمهورية مصر العربية","common":"مصر"}}
$egypt->getDataProtection()                         $egypt->getNativeNames();

// {"iso_4217_code":"EGP","iso_4217_numeric":818,"iso_4217_name":"Egyptian Pound","iso_4217_minor_unit":2}
$egypt->getCurrency();

// {"EGP":{"iso_4217_code":"EGP","iso_4217_numeric":818,"iso_4217_name":"Egyptian Pound","iso_4217_minor_unit":2}}
$egypt->getCurrencies();

// {"ara":{"official":"جمهورية مصر العربية","common":"مصر"},"cym":{"official":"Arab Republic of Egypt","common":"Yr Aifft"},"deu":{"official":"Arabische Republik Ägypten","common":"Ägypten"},"fra":{"official":"République arabe d'Égypte","common":"Égypte"},"hrv":{"official":"Arapska Republika Egipat","common":"Egipat"},"ita":{"official":"Repubblica araba d'Egitto","common":"Egitto"},"jpn":{"official":"エジプト·アラブ共和国","common":"エジプト"},"nld":{"official":"Arabische Republiek Egypte","common":"Egypte"},"por":{"official":"República Árabe do Egipto","common":"Egito"},"rus":{"official":"Арабская Республика Египет","common":"Египет"},"spa":{"official":"República Árabe de Egipto","common":"Egipto"},"fin":{"official":"Egyptin arabitasavalta","common":"Egypti"}}
$egypt->getTranslations();

// {"continent":{"AF":"Africa"},"postal_code":true,"latitude":"27 00 N","latitude_dec":"26.756103515625","longitude":"30 00 E","longitude_dec":"29.86229705810547","max_latitude":"31.916667","max_longitude":"36.333333","min_latitude":"20.383333","min_longitude":"24.7","area":1002450,"region":"Africa","subregion":"Northern Africa","world_region":"EMEA","region_code":"002","subregion_code":"015","landlocked":false,"borders":["ISR","LBY","SDN"],"independent":"Yes"}
$egypt->getGeodata();

// {"geonameid":357994,"edgar":"H2","itu":"EGY","marc":"ua","wmo":"EG","ds":"ET","fifa":"EGY","fips":"EG","gaul":40765,"ioc":"EGY","cowc":"EGY","cown":651,"fao":59,"imf":469,"ar5":"MAF","address_format":"{{recipient}}\n{{street}}\n{{postalcode}} {{city}}\n{{country}}","eu_member":null,"data_protection":"Other","vat_rates":null,"emoji":"🇪🇬"}
$egypt->getExtra();

// {"name":"Al Iskandariyah","alt_names":["El Iskandariya","al-Iskandariyah","al-Iskandarīyah","Alexandria","Alexandrie","Alexandria"],"geo":{"latitude":31.2000924,"longitude":29.9187387,"min_latitude":31.1173177,"min_longitude":29.8233701,"max_latitude":31.330904,"max_longitude":30.0864016}}
$egypt->getDivision("ALX");

注意: 当检索单个国家时,您将获得与上一个示例一样的完整国家详细信息。但当检索所有国家时,您将获得一个简短的国家列表,其中包含常见的国家详细信息,以提高性能。

特性说明

  • 国家数据都存储在这里: resources/data/countries.json
  • name
    • common - 英文常用名
    • official - 英文官方名
    • native - 所有本地名的列表
      • key: 三字母ISO 639-3语言代码
      • value: 名称对象
        • key: official - 官方名翻译
        • key: common - 常用名翻译
  • demonym - 居民名称
  • capital - 首都城市
  • iso_3166_1_alpha2 - ISO 3166-1 alpha-2代码
  • iso_3166_1_alpha3 - ISO 3166-1 alpha-3代码
  • iso_3166_1_numeric - ISO 3166-1数字代码
  • currency - ISO 4217货币代码(s)
    • key: 三字母ISO 4217货币代码
    • value: 货币对象
      • key: iso_4217_code - 三字母ISO 4217货币字母代码
      • key: iso_4217_numeric - 三数字ISO 4217货币数字代码
      • key: iso_4217_name - 官方ISO 4217货币名称
      • key: iso_4217_minor_unit - 小货币单位
  • tld - 国家代码顶级域名
  • alt_spellings - 替代拼写
  • languages - 官方语言列表
    • key: 三字母ISO 639-3语言代码
    • value: 英语中的语言名称
  • translations - 名称翻译列表
    • key: 三字母ISO 639-3语言代码
    • value: 名称对象
      • key: official - 官方名翻译
      • key: common - 常用名翻译
  • geo
    • continent - 国家所在的洲
      • key: 双字母洲代码
      • value: 英语中的洲名称
    • postal_code - 该国家是否使用邮政编码
    • latitude - 纬度坐标点的简短形式
    • latitude_desc - 描述纬度坐标点
    • longitude - 经度坐标点的简短形式
    • longitude_desc - 描述经度坐标点
    • max_latitude - 最大纬度坐标点
    • max_longitude - 最大经度坐标点
    • min_latitude - 最小纬度坐标点
    • min_longitude - 最小经度坐标点
    • area - 面积(平方公里)
    • region - 地理区域
    • subregion - 地理子区域
    • world_region - 地理世界区域
    • region_code - 地理区域数字代码
    • subregion_code - 地理子区域数字代码
    • landlocked - 陆地锁定状态
    • borders - 陆地边界
    • independent - 独立状态
  • 拨号
    • calling_code - 区号
    • national_prefix - 国家前缀
    • national_number_lengths - 国家号码长度
    • national_destination_code_lengths - 国家目的地代码长度
    • international_prefix - 国际前缀
  • 额外
    • geonameid - 地名ID
    • edgar - 电子数据收集、分析和检索系统
    • itu - 国际电信联盟分配的代码
    • marc - 美国国会图书馆的机器可读编目代码
    • wmo - 世界气象组织国家缩写
    • ds - 国际交通车辆区分标志
    • fifa - 国际足球联合会分配的代码
    • fips - 美国联邦信息处理标准代码
    • gaul - 联合国粮食及农业组织全球行政单元层
    • ioc - 国际奥委会分配的代码
    • cowc - 战争相关性字符
    • cown - 战争相关性数字
    • fao - 联合国粮食及农业组织
    • imf - 国际货币基金组织
    • ar5 - 第五次评估报告(AR5)
    • address_format - 地址格式
    • eu_member - 欧盟成员国
    • data_protection - 数据保护
    • vat_rates - 增值税率
    • emoji - 表情旗

数据来源

升级

变更日志

请参阅变更日志以了解项目的完整历史。

支持

以下支持渠道随时可用

贡献 & 协议

感谢您考虑为此项目做出贡献!贡献指南可以在CONTRIBUTING.md中找到。

欢迎提交错误报告、功能请求和拉取请求。

安全漏洞

如果您在此项目中发现安全漏洞,请发送电子邮件至help@grnspc.com。所有安全漏洞都将得到及时处理。

许可证

本软件采用MIT许可(MIT)发布。

版权所有(c)2020-2023 GrnSpc LLC,部分权利保留。