adamlc/address-format

一个PHP库,用于将街道地址解析成本地化格式

1.5.0 2023-08-07 07:30 UTC

This package is auto-updated.

Last update: 2024-09-07 13:16:32 UTC


README

Latest Version Software License GitHub Workflow Status Total Downloads

一个PHP库,用于将街道地址解析成本地化格式。地址格式基于Google的libaddressinput提供的格式。

我已经编写了一些基本的单元测试,但它们可能需要改进。如果您改进了它们,请随时提交pull request!

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