PHPackages                             jord-jd/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jord-jd/php-postcodes

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jord-jd/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(3mo ago)584[1 issues](https://github.com/Jord-JD/php-postcodes/issues)2LGPL-3.0-onlyPHPPHP ^7.1||^8.0

Since Jan 16Pushed 3mo agoCompare

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

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

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

49

—

FairBetter than 95% of packages

Maintenance78

Regular maintenance activity

Popularity13

Limited adoption so far

Community17

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

93d 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/jord-jd-php-postcodes/health.svg)

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

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[blair2004/nexopos

The Free Modern Point Of Sale System build with Laravel, TailwindCSS and Vue.js.

1.2k2.3k](/packages/blair2004-nexopos)[niiknow/bayes

a machine learning lib

6950.0k](/packages/niiknow-bayes)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[amirezaeb/heroqr

A Powerful QR Code Management Library For PHP

9510.3k](/packages/amirezaeb-heroqr)

PHPackages © 2026

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