PHPackages                             torann/address-format - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. torann/address-format

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

torann/address-format
=====================

A PHP library to parse street addresses to localized formats

2.0.0(1y ago)54.7k↓100%BSD-2-ClausePHPPHP ^8.2

Since Oct 12Pushed 1y ago2 watchersCompare

[ Source](https://github.com/Torann/address-format)[ Packagist](https://packagist.org/packages/torann/address-format)[ RSS](/packages/torann-address-format/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

Address Format
==============

[](#address-format)

[![Build Status](https://camo.githubusercontent.com/29def4c992454ff10ff84cf465f29e39b8597d9fcd8a54bcb8d6074f1efd813a/68747470733a2f2f7472617669732d63692e6f72672f546f72616e6e2f616464726573732d666f726d61742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Torann/address-format)[![Latest Stable Version](https://camo.githubusercontent.com/5b240dad2b568a51d329698a8470d3e9c2b8ba9e2fb9169c4ec02878b9225c54/68747470733a2f2f706f7365722e707567782e6f72672f746f72616e6e2f616464726573732d666f726d61742f762f737461626c652e706e67)](https://packagist.org/packages/torann/address-format)[![Total Downloads](https://camo.githubusercontent.com/498239d2c949b8e9d2ed285ad5b202700d0325f3d4080db44a832edf792baaa1/68747470733a2f2f706f7365722e707567782e6f72672f746f72616e6e2f616464726573732d666f726d61742f646f776e6c6f6164732e706e67)](https://packagist.org/packages/torann/address-format)[![Patreon donate button](https://camo.githubusercontent.com/f9e075baad95563481d35174d43ef50757281abb6bc795d0f473fad452afa030/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617472656f6e2d646f6e6174652d79656c6c6f772e737667)](https://www.patreon.com/torann)[![Donate weekly to this project using Gratipay](https://camo.githubusercontent.com/0eeae019980adaa1dc64842cfb01f3d738c688982ea4eb58094047011cb46704/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f67726174697061792d646f6e6174652d79656c6c6f772e737667)](https://gratipay.com/~torann)[![Donate to this project using Flattr](https://camo.githubusercontent.com/d79e412f78041f87e203449041ad81848a8405cf0f3c622c51e3bad0c2a4b599/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f666c617474722d646f6e6174652d79656c6c6f772e737667)](https://flattr.com/profile/torann)[![Donate to this project using Paypal](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4CJA2A97NPYVU)

A PHP library to parse street addresses to localized formats. The address formats are based on the formats supplied by Google's libaddressinput.

Installation
------------

[](#installation)

- [Address Format on Packagist](https://packagist.org/packages/torann/address-format)
- [Address Format on GitHub](https://github.com/torann/address-format)

### Composer

[](#composer)

From the command line run:

```
$ composer require torann/address-format
```

Usage
-----

[](#usage)

### Formatting

[](#formatting)

`format(array $data, $html = false)`

**Arguments:**

- `$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](http://schema.org/PostalAddress) schema.

**Usage:**

```
$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:

```
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*.

Custom Country Formats
----------------------

[](#custom-country-formats)

This allows you to set your own formats.

`setFormats(array $countries)`

**Arguments:**

- `$countries` - An array of country ISO codes and corresponding formats values.

**Usage:**

```
\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
--------------------

[](#available-attributes)

AttributeFormat KeyCommon Nameadmin\_areaSstatelocalityCcityrecipientNperson's nameorganizationOorganizationdependent\_localityDpostal\_codeZzip codesorting\_codeXstreet\_addressAcountryRChange Log
----------

[](#change-log)

#### v1.0.0

[](#v100)

- First release

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2980 days

Total

2

Last Release

521d ago

Major Versions

1.0.0 → 2.0.02024-12-10

PHP version history (2 changes)1.0.0PHP &gt;=5.5.9

2.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/b740fab755b353680beb41191f3b6195d84d9811662960d07f2bf64fde2f7c64?d=identicon)[torann](/maintainers/torann)

---

Top Contributors

[![Torann](https://avatars.githubusercontent.com/u/1406755?v=4)](https://github.com/Torann "Torann (6 commits)")

---

Tags

address formatstreet addresseslocalized formats

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/torann-address-format/health.svg)

```
[![Health](https://phpackages.com/badges/torann-address-format/health.svg)](https://phpackages.com/packages/torann-address-format)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M345](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
