nicoka49 / address-format
一个用于将街道地址解析为本地化格式的PHP库
1.0.1
2022-09-20 15:28 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-09-20 19:55:42 UTC
README
这是一个用于将街道地址解析为本地化格式的PHP库。地址格式基于Google的libaddressinput提供的格式。
我已经编写了一些基本的单元测试,但它们可能还需要改进。如果您能改进它们,请随时提交拉取请求!
Composer
要将AddressFormat安装为Composer包,请将以下内容添加到您的composer.json文件中
"adamlc/address-format": "~1.3"
运行 composer update
格式化街道地址
//Create an address formatter 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目录以查看地区元数据。
以下属性可用
ADMIN_AREA
LOCALITY
RECIPIENT
ORGANIZATION
DEPENDENT_LOCALITY
POSTAL_CODE
SORTING_CODE
STREET_ADDRESS
COUNTRY