PHPackages                             divineomega/php-postcodes - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. divineomega/php-postcodes

Abandoned → [jord-jd/php-postcodes](/?search=jord-jd%2Fphp-postcodes)Library[Validation &amp; Sanitization](/categories/validation)

divineomega/php-postcodes
=========================

This library handles various UK postcode related tasks such as address lookup by postcode, postcode validation, generation of valid UK postcodes and getting a postcode's outward and inward codes.

v5.0.0(4mo ago)611.2k↓71.7%4[1 issues](https://github.com/Jord-JD/php-postcodes/issues)LGPL-3.0-onlyPHPPHP ^7.1||^8.0CI failing

Since Jan 16Pushed 4mo agoCompare

[ Source](https://github.com/Jord-JD/php-postcodes)[ Packagist](https://packagist.org/packages/divineomega/php-postcodes)[ Docs](https://github.com/Jord-JD/php-postcodes)[ GitHub Sponsors](https://github.com/DivineOmega)[ RSS](/packages/divineomega-php-postcodes/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (3)Versions (23)Used By (0)

PHP Postcodes
=============

[](#php-postcodes)

[![Build Status](https://camo.githubusercontent.com/a94169b43690dab375271794126928e30d396ceb58e257fcd82098d926381d5d/68747470733a2f2f7472617669732d63692e636f6d2f4a6f72642d4a442f7068702d706f7374636f6465732e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/Jord-JD/php-postcodes)[![Coverage Status](https://camo.githubusercontent.com/5439fbcb8793fb196e389145c207cd8b5a4b85e4c343ed3b93452e319cc26ad2/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4a6f72642d4a442f7068702d706f7374636f6465732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Jord-JD/php-postcodes?branch=master)[![StyleCI](https://camo.githubusercontent.com/2334f4b5cb62f1496f0c5186e2b2cc57a1b4580ea7fb2c432e2430477e7a8565/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3136373939303932342f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/167990924)[![Packagist](https://camo.githubusercontent.com/18cd83cfe070fedfa73e11b893f3b5e6db9a396239c6b8a610cf23562f9194a5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f72642d6a642f7068702d706f7374636f6465732e737667)](https://packagist.org/packages/jord-jd/php-postcodes/stats)

This library handles various UK postcode related tasks.

Features
--------

[](#features)

- Address lookup by postcode
- Postcode validation
- Generate valid UK postcodes
- Get a postcode's outward and inward codes

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

[](#installation)

To install, just run the following composer command.

`composer require jord-jd/php-postcodes`

Setup
-----

[](#setup)

### Postcode Lookup Services

[](#postcode-lookup-services)

Using some of the data retrieval features provided by this library requires a postcode lookup service. It currently supports the following postcode lookup services.

- Ideal Postcodes -
- Postcode Anywhere (PCA Predict) -
- Postcodes.io -

Sign up at the respective website if you need to use these features.

You can then use the following code to get an appropriate postcode lookup service object.

```
$postcodeLookupService = new \JordJD\Postcodes\Objects\IdealPostcodes('API_KEY');
// OR
$postcodeLookupService = new \JordJD\Postcodes\Objects\PostcodeAnywhere('API_KEY');
// OR
$postcodeLookupService = new \JordJD\Postcodes\Objects\PostcodesIo();
```

Usage
-----

[](#usage)

### Get addresses by postcode

[](#get-addresses-by-postcode)

To retrieve the addresses associated with a UK postcode, just pass it to the method shown below. You will receive an array of address objects, appropriately split by their address lines and other details.

```
$addresses = $postcodeLookupService->getAddressesByPostcode('ST163DP');
```

### Validate postcode

[](#validate-postcode)

You can validate a UK postcode is correct using the `Validator` utility class. An example of how to do so is shown below.

```
$validated = \JordJD\Postcodes\Utils\Validator::validatePostcode('ST163DP');
```

Please note that the postcode validation is case insensitive.

### Generate postcode

[](#generate-postcode)

This library allows you generate a random, valid UK postcode. This makes use of the `Generator` utility class, as shown below.

```
$postcode = \JordJD\Postcodes\Utils\Generator::generatePostcode();
```

### Get outward and inward codes

[](#get-outward-and-inward-codes)

> The first part of the Postcode eg PO1 is called the outward code as it identifies the town or district to which the letter is to be sent for further sorting. The second part of the postcode eg 1EB is called the inward code.

```
$outwardCode = \JordJD\Postcodes\Utils\Tokenizer::outward('ST163DP'); // Returns ST16
$inwardCode = \JordJD\Postcodes\Utils\Tokenizer::inward('ST163DP'); // Returns 3DP
```

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance71

Regular maintenance activity

Popularity31

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 83.8% 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 ~158 days

Recently: every ~479 days

Total

22

Last Release

139d ago

Major Versions

v1.2.1 → v2.0.02017-06-22

v2.2.0 → v3.0.02019-01-28

v3.0.1 → v4.0.02019-04-16

v4.6.0 → v5.0.02026-02-14

PHP version history (3 changes)v1.0.0PHP &gt;=5.5.9

v4.0.0PHP ^7.1

v4.4.0PHP ^7.1||^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/c580cdf7c14898fff179cdfc1085892091d5d2f49d917873a12365af9ac77c93?d=identicon)[Jord-JD](/maintainers/Jord-JD)

---

Top Contributors

[![Jord-JD](https://avatars.githubusercontent.com/u/650645?v=4)](https://github.com/Jord-JD "Jord-JD (31 commits)")[![kirsty-gasston](https://avatars.githubusercontent.com/u/12949343?v=4)](https://github.com/kirsty-gasston "kirsty-gasston (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![ash123456789](https://avatars.githubusercontent.com/u/11010491?v=4)](https://github.com/ash123456789 "ash123456789 (1 commits)")[![LNCH](https://avatars.githubusercontent.com/u/10821244?v=4)](https://github.com/LNCH "LNCH (1 commits)")

---

Tags

php-libraryphp-postcodespostcodepostcode-lookup-librarypostcode-validationuk-postcodephpPHP LibrarypostcodesPHP postcodes libraryPHP postcodes

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/divineomega-php-postcodes/health.svg)

```
[![Health](https://phpackages.com/badges/divineomega-php-postcodes/health.svg)](https://phpackages.com/packages/divineomega-php-postcodes)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M737](/packages/sylius-sylius)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[aporat/store-receipt-validator

PHP receipt validator for Apple App Store and Amazon Appstore

6544.0M13](/packages/aporat-store-receipt-validator)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M47](/packages/tencentcloud-tencentcloud-sdk-php)[elgg/elgg

Elgg is an award-winning social networking engine, delivering the building blocks that enable businesses, schools, universities and associations to create their own fully-featured social networks and applications.

1.7k16.4k79](/packages/elgg-elgg)

PHPackages © 2026

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