address format
1.5.0
一个 PHP 库,用于将街道地址解析为本地化格式。 address format基于 Google 的 libaddressinput 提供的格式。
我已经编写了一些基本的单元测试,但它们可能还可以改进。如果您改进了它们,请随时提交拉取请求!
要将 AddressFormat 安装为 Composer 包,请将其添加到您的composer.json:
"adamlc/address-format" : " ~1.3 "
运行composer update
//Create an address format ter instance
$ address_formatter = new Adamlc AddressFormat Format ;
//Set a locale using a two digit ISO country code.
$ address_formatter -> setLocale ( ' GB ' );
//Set the address parts / attributes
$ address_formatter [ ' ADMIN_AREA ' ] = ' London ' ;
$ address_formatter [ ' LOCALITY ' ] = ' Greenwich ' ;
$ address_formatter [ ' RECIPIENT ' ] = ' Joe Bloggs ' ;
$ address_formatter [ ' ORGANIZATION ' ] = ' Novotel London ' ;
$ address_formatter [ ' POSTAL_CODE ' ] = ' SE10 8JA ' ;
$ address_formatter [ ' STREET_ADDRESS ' ] = ' 173-185 Greenwich High Road ' ;
$ address_formatter [ ' COUNTRY ' ] = ' United Kingdom ' ;
//Get the address in localised format
$ html = true ; // Optional - return the address in HTML <br> instead of n new lines
echo $ address_formatter -> formatAddress ( $ html );
上面的代码将产生以下结果:
Joe Bloggs
Novotel London
173-185 Greenwich High Road
Greenwich
London
SE10 8JA
注意:查看 i18n 目录以查看语言环境的元数据。
以下属性可用:
管理区
地点
接受者
组织
DEPENDENT_LOCALITY
邮政编码
排序代码
街道地址
国家