php postcodes
v4.6.0
该库处理各种英国邮政编码相关的任务。
要安装,只需运行以下作曲家命令即可。
composer require divineomega/php-postcodes
使用此库提供的一些数据检索功能,需要一个后代码查找服务。它目前支持以下邮政编码查找服务。
如果您需要使用这些功能,请在相应的网站上注册。
然后,您可以使用以下代码获取适当的邮政编码查找服务对象。
$ postcodeLookupService = new DivineOmega Postcodes Objects IdealPostcodes ( ' API_KEY ' );
// OR
$ postcodeLookupService = new DivineOmega Postcodes Objects PostcodeAnywhere ( ' API_KEY ' );
// OR
$ postcodeLookupService = new DivineOmega Postcodes Objects PostcodesIo ();要检索与英国邮政编码相关的地址,只需将其传递到下面所示的方法。您将收到一系列地址对象,并由其地址行和其他详细信息适当分配。
$ addresses = $ postcodeLookupService -> getAddressesByPostcode ( ' ST163DP ' );您可以使用Validator公用事业类”验证英国邮政编码是正确的。下面显示了一个方法的示例。
$ validated = DivineOmega Postcodes Utils Validator:: validatePostcode ( ' ST163DP ' );请注意,邮政编码验证是不敏感的。
该库允许您生成一个随机的,有效的英国邮政编码。这利用了Generator实用程序类,如下所示。
$ postcode = DivineOmega Postcodes Utils Generator:: generatePostcode ();邮政编码的第一部分,例如PO1,称为外部代码,因为它标识了将要向该信发送的城镇或地区进行进一步分类。邮政编码的第二部分(例如1EB)称为内部代码。
$ outwardCode = DivineOmega Postcodes Utils Tokenizer:: outward ( ' ST163DP ' ); // Returns ST16
$ inwardCode = DivineOmega Postcodes Utils Tokenizer:: inward ( ' ST163DP ' ); // Returns 3DP