grmule / php-ziptastic
该包已被弃用且不再维护。未建议替代包。
一个简单的类,用于访问 Ziptastic API(https://www.getziptastic.com/)
1.0.0
2015-05-05 17:23 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2023-10-14 12:12:39 UTC
README
一个简单的 PHP 类,用于访问 Ziptastic API。
示例用法
$zt = new PHPZiptastic\Ziptastic(49504); print $zt->city; // Grand Rapids print $zt->lookup(34231)->city; // Sarasota print $zt->lookup(44870); // Bloomingville, OH print json_encode($zt); // {"city":"Bloomingville","state":"OH","zip":"44870"}
错误和异常
默认情况下,错误(找不到邮编、传入的邮编格式不正确)会在 $error 属性中放置一条消息,并返回自身引用。这看起来像
print $zt->lookup(12344)->city; // null print $zt->error; // Invalid zip code
如果您想捕获异常,请将 TRUE 作为构造函数的第二个参数传递
$zt = new Ziptastic(null, true); $zt->lookup(12344); // exception thrown here
或者
$zt = new Ziptastic(12344, true); // exception thrown here
对于所有错误,异常抛出是 PHP 基础异常类。
安装
包含 Ziptastic.php 或安装 composer 包。
Ziptastic
Ziptastic 是一个简单的 API,允许人们询问与邮编关联的国家、州和城市。
更多信息请访问 http://daspecster.github.com/ziptastic/
非常感谢 ElevenBaseTwo(《http://blog.elevenbasetwo.com/》)简化了我们的表单!