przem16 / address-formatter
Address formatter using country templates from https://github.com/OpenCageData/address-formatting
v1.0.0
2026-08-19 12:24 UTC
Requires
- php: >=7.1.3
- mustache/mustache: ^3.2
- symfony/yaml: >=4.0
Requires (Dev)
- phpunit/phpunit: ^13.3
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-08-19 12:36:49 UTC
README
This library uses the address templates from https://github.com/OpenCageData/address-formatting to format addresses differently depending on the country.
Requirements
- PHP 7.1.3 or later
Installation
Install the latest version with Composer:
composer require przem16/address-formatter
Examples
You can use either the Address object or provide an array of address parts.
use PredictHQ\AddressFormatter\Address; $address = new Address(); $address->setCity('Wellington') ->setCountry('New Zealand') ->setCountryCode('NZ') ->setCounty('Wellington City') ->setHouseNumber(53) ->setPostcode(6011) ->setRoad('Pirie Street') ->setState('Wellington') ->setSuburb('Mount Victoria'); $text = $address->format(); /** * Will display as: * * 53 Pirie Street * Mount Victoria * Wellington 6011 * New Zealand */ echo $text;
Or, pass an array of address parts to the Formatter.
use PredictHQ\AddressFormatter\Formatter; $address = [ 'city' => 'Wellington', 'country' => 'New Zealand', 'country_code' => 'NZ', 'county' => 'Wellington City', 'house_number' => 53, 'postcode' => 6011, 'road' => 'Pirie Street', 'state' => 'Wellington', 'suburb' => 'Mount Victoria', ]; /** * Will display as: * * 53 Pirie Street * Mount Victoria * Wellington 6011 * New Zealand */ $formatter = new Formatter(); $text = $formatter->formatArray($address);
Tests
Run tests using ./vendor/bin/phpunit