, (*1)
A PHP library to parse street addresses to localized formats. The address formats are based on the formats supplied by Google's libaddressinput., (*2)
Installation
Composer
From the command line run:, (*3)
$ composer require torann/address-format
Usage
format(array $data, $html = false), (*4)
Arguments:, (*5)
-
$data - An array of address elements
-
$html - When set to true the address elements will be wrapped with span tags.
NOTE: The wrapping span tags contain itemprop attributes that adhere to the PostalAddress schema., (*6)
Usage:, (*7)
$address = \Torann\AddressFormat\Address::format([
'recipient' => 'Jane Doe',
'organization' => 'Whitworth Institute Inc.',
'street_address' => '20341 Whitworth Institute',
'street_address_2' => '405 N. Whitworth',
'locality' => 'Seattle',
'admin_area' => 'WA',
'postal_code' => '98052',
'country_iso' => 'US',
]);
The above code will produce the following:, (*8)
Jane Doe
Whitworth Institute Inc.
20341 Whitworth Institute
405 N. Whitworth
Seattle, WA 98052
NOTE: The country_iso attribute is used to determine the address's format. The default is set to US., (*9)
This allows you to set your own formats., (*10)
setFormats(array $countries), (*11)
Arguments:, (*12)
-
$countries - An array of country ISO codes and corresponding formats values.
Usage:, (*13)
\Torann\AddressFormat\Address::setFormats([
'GB' => '%N%n%O%n%A%n%C%n%Z %R',
'US' => '%N%n%O%n%A%n%C, %S %Z %R',
]);
Available Attributes
| Attribute |
Format Key |
Common Name |
| admin_area |
S |
state |
| locality |
C |
city |
| recipient |
N |
person's name |
| organization |
O |
organization |
| dependent_locality |
D |
| postal_code |
Z |
zip code |
| sorting_code |
X |
| street_address |
A |
| country |
R |
Change Log
v1.0.0