datingvip / geo
地理数据助手
v1.0.10
2018-04-17 09:30 UTC
Requires
- php: >=5.4.0
README
地理数据助手
ISO / FIPS 码转换
将 FIPS 10-4
转换为 ISO 3166-1
码,或反之
require_once 'vendor/autoload.php'; use DatingVIP\geo\Country_Code; echo (new Country_Code)->fips2iso ('SG'); // outputs: SN echo (new Country_Code)->iso2fips ('PR'); // outputs: RQ
邮政编码验证
验证或解析几乎任何国家的邮政编码(使用正则表达式)。国家代码接受 ISO 3166-1
格式。
require_once 'vendor/autoload.php'; use DatingVIP\geo\Postal_Code; use DatingVIP\geo\Validation_Exception; $postal_code = new Postal_Code (); // check if country is covered var_dump ($postal_code->coveringCountry ('SG')); // bool(true) // get an array of human readable postal code formats for given country var_dump ($postal_code->getFormats ('RS')); // array(1) { // [0]=> // string(5) "#####" //} // check if zip code is valid var_dump ($postal_code->isValid ('RS', '11000')); // bool(true) try { $postal_code->isValid ('WW', '....'); } catch (Validation_Exception $e) { var_dump ($e->getMessage()); // string(26) "Invalid country code: "WW"" } if ($postal_code->contains ('RS', '11000, Beograd')) { var_dump ($postal_code->capture ('RS', '11000, Beograd')); // string(5) "11000" }
通配符到正则表达式的映射
#
=0-9
@
=a-zA-Z
*
=a-zA-Z0-9
州代码
ISO 3166-2
主要行政区域(省、州、地区)实用类
require_once 'vendor/autoload.php'; use DatingVIP\geo\State_Code; $state_code = new State_Code (); // get available states/regions in given country var_dump ($state_code->getCountry ('CY')); //array(6) { // ["04"]=> // string(12) "Ammóchostos" // ["06"]=> // string(9) "Kerýneia" // ["03"]=> // string(8) "Lárnaka" // ["01"]=> // string(9) "Lefkosía" // ["02"]=> // string(8) "Lemesós" // ["05"]=> // string(6) "Páfos" //} // get region/state name based on given code var_dump ($state_code->getName ('CY', '02')); //string(8) "Lemesós" // get region/state code based on given name var_dump ($state_code->get ('US', 'Alabama')); //string(2) "AL" // check if given country / state code combo is valid var_dump ($state_code->isValid ('AB', 'CD')); //bool(false) // check if given country / state code combo is valid var_dump ($state_code->isValid ('RS', '03')); //bool(true)