grnspc / countries
Countries 是一个简单且轻量级的包,用于灵活检索国家详细信息。只需轻轻一点,您就能获得250个国家的详细信息,包括名称、通称、首都、ISO代码、电话区号、地理数据、货币、国旗、表情符号以及其他属性。
v0.1.0
2023-02-27 15:34 UTC
Requires
- php: ^8.1.0
Requires (Dev)
- laravel/pint: ^1.6
- pestphp/pest: 2.x-dev
- phpstan/phpstan: ^1.10
README
GRNSPC Country 是一个简单且轻量级的包,用于灵活检索国家详细信息。您只需轻轻一点,就能获得250个国家的详细信息,包括名称、通称、首都、ISO代码、电话区号、地理数据、货币、国旗、表情符号以及其他属性。
用法
使用 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
- 常用名翻译
- key:
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
- 小货币单位
- key:
tld
- 国家代码顶级域名alt_spellings
- 替代拼写languages
- 官方语言列表- key: 三字母ISO 639-3语言代码
- value: 英语中的语言名称
translations
- 名称翻译列表- key: 三字母ISO 639-3语言代码
- value: 名称对象
- key:
official
- 官方名翻译 - key:
common
- 常用名翻译
- key:
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
- 地名IDedgar
- 电子数据收集、分析和检索系统itu
- 国际电信联盟分配的代码marc
- 美国国会图书馆的机器可读编目代码wmo
- 世界气象组织国家缩写ds
- 国际交通车辆区分标志fifa
- 国际足球联合会分配的代码fips
- 美国联邦信息处理标准代码gaul
- 联合国粮食及农业组织全球行政单元层ioc
- 国际奥委会分配的代码cowc
- 战争相关性字符cown
- 战争相关性数字fao
- 联合国粮食及农业组织imf
- 国际货币基金组织ar5
- 第五次评估报告(AR5)address_format
- 地址格式eu_member
- 欧盟成员国data_protection
- 数据保护vat_rates
- 增值税率emoji
- 表情旗
数据来源
- 货币数据(2016年9月27日):http://www.currency-iso.org
- 表情旗(2016年9月27日):http://unicode.org/emoji/charts/full-emoji-list.html
- 世界边界(2016年9月27日):http://thematicmapping.org/downloads/world_borders.php
- GeoJson & SVG 旗(2016年9月27日):https://github.com/mledoze/countries/tree/master/data
- 主要国家数据、地区和分区(2016年9月27日):https://github.com/hexorx/countries
- 其他资源
- https://en.wikipedia.org
- https://github.com/annexare/Countries
- https://github.com/umpirsky/country-list
- https://github.com/datasets/country-list
- https://github.com/datasets/country-codes
- https://github.com/sripaulgit/country-codes
- https://github.com/alexrabarts/iso_country_codes
- https://github.com/vincentarelbundock/countrycode
- https://github.com/lukes/ISO-3166-Countries-with-Regional-Codes
升级
变更日志
请参阅变更日志以了解项目的完整历史。
支持
以下支持渠道随时可用
贡献 & 协议
感谢您考虑为此项目做出贡献!贡献指南可以在CONTRIBUTING.md中找到。
欢迎提交错误报告、功能请求和拉取请求。
安全漏洞
如果您在此项目中发现安全漏洞,请发送电子邮件至help@grnspc.com。所有安全漏洞都将得到及时处理。
许可证
本软件采用MIT许可(MIT)发布。
版权所有(c)2020-2023 GrnSpc LLC,部分权利保留。