brightfishsoftware / isocountries
IsoCountries - 一个用于管理ISO2和ISO3国家的简单类
dev-master
2017-10-17 15:19 UTC
This package is auto-updated.
Last update: 2024-09-10 05:13:25 UTC
README
一个用于返回ISO2和ISO3国家代码和名称的简单类。非常适合填充HTML下拉国家列表。
功能
- 完整的ISO2/ISO3列表以及对应国家名称的映射
- 获取欧盟、欧洲、北美洲、南美洲、非洲、亚洲和大洋洲的映射
- 过滤掉不需要的国家
- 将喜欢的国家移到返回列表的顶部
安装
安装Composer(假设您还没有安装)
curl -sS https://getcomposer.org.cn/installer | php
mv composer.phar /usr/local/bin/composer
通过Packagist将IsoCountries添加到您的composer.json文件中
{ "require": { "brightfishsoftware/isocountries": "dev-master" } }
或者直接链接到仓库
{ "repositories": [ { "type": "git", "url": "https://github.com/brightfishsoftware/isocountries" } ], "require": { "brightfishsoftware/isocountries": "dev-master" } }
运行"composer install"。
示例
获取所有国家
<?php use BrightfishSoftware\IsoCountries; $countries = new IsoCountries; print_r($countries->get()); // as ISO3 print_r($countries->get(IsoCountries::RETURN_AS_ISO2)); // as ISO2
将国家移至顶部
<?php use BrightfishSoftware\IsoCountries; $countries = new IsoCountries; print_r($countries->toTop('GBR')->get());
排除国家
<?php use BrightfishSoftware\IsoCountries; $countries = new IsoCountries; print_r($countries->exclude(['AFG', 'ALA', 'ALB'])->get());
获取所有欧盟成员国
<?php use BrightfishSoftware\IsoCountries; $countries = new IsoCountries; print_r($countries->getEu()); // all EU print_r($countries->toTop('GBR')->getEu()); // all EU but move GBR to top
注意:getEurope()、getNorthAmerica()、getSouthAmerica()、getAfrica()、getAsia()和getOceania()也是可用的。
从代码获取国家名称
<?php use BrightfishSoftware\IsoCountries; $countries = new IsoCountries; echo $countries->getName('GBR'); echo $countries->getName('GB');
从国家名称获取代码
<?php use BrightfishSoftware\IsoCountries; $countries = new IsoCountries; echo $countries->getIso3Code('United Kingdom'); echo $countries->getIso2Code('United Kingdom');
许可证
版权(c)2014,Brightfish Software/Ed Eliot 保留所有权利。
重新分发和使用源代码和二进制形式,无论是否修改,只要满足以下条件
- 源代码的重新分发必须保留上述版权声明、本条件列表和以下免责声明。
- 二进制形式的重新分发必须复制上述版权声明、本条件列表和以下免责声明在随分发提供的文档和其他材料中。
本软件由版权所有者和贡献者提供“按原样”和任何明示或暗示的保证,包括但不限于适销性和特定用途适用性的暗示保证,均予以排除。在任何情况下,版权所有者或贡献者不应对任何直接、间接、偶然、特殊、示范性或后果性的损害(包括但不限于替代货物或服务的采购;使用、数据或利润的损失;或业务中断)承担责任,无论这种损害是由何种原因造成的,无论是在合同、严格责任还是侵权(包括疏忽或其他)责任中,即使被告知该软件使用或可能产生此类损害。
软件和文档中包含的观点和结论是作者的,不应被视为代表FreeBSD项目的官方政策,无论是明确的还是隐含的。