carloswph / ibgecode-php
一个简单的库,用于从IBGE代码中检索巴西的城市及其相应的州。
v1.0.1
2021-02-05 18:21 UTC
Requires
- php: >=7.0.1
This package is auto-updated.
Last update: 2024-09-13 04:59:29 UTC
README
一个简单的库,用于从IBGE代码中检索巴西的城市及其相应的州。
安装
只需使用Composer要求库:composer require carloswph/ibgecode-php
。
用法
简单自动加载并实例化IBGE类 - 包括作为参数的搜索代码数组。从初始实例开始,该类允许获取相应的城市、州或两者。所有方法都返回结果数组。
use WPH\IBGE\IBGE; require __DIR__ . '/vendor/autoload.php'; $try = new IBGE(['5200050', '2300101', '99999999999']); $try->getCity(); // return an array of city names for each code $try->getState(); // return an array of state codes for those $try->getBoth(); // return an array of arrays, each with key-value pairs for cities and state codes
还有一个附加的链式方法可以返回JSON,如下所示。
$try = new IBGE(['5200050', '2300101', '99999999999']); $try->getCity(); // return an array of city names for each code $json = $try->toJson(); echo $json; // Results in: // [{"cidade":"Abadia de Goi\u00e1s","estado":"GO"},{"cidade":"Abaiara","estado":"CE"},["C\u00f3digo Inexistente."]] // The toJson() method admits the parameter true, which returns the JSON response in pretty print format.