PHPackages                             rapidwebltd/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. rapidwebltd/php-postcodes

ActiveLibrary

rapidwebltd/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.

v2.2.0(8y ago)03.3k4[1 PRs](https://github.com/rapidwebltd/php-postcodes/pulls)LGPL-3.0-onlyPHPPHP &gt;=5.5.9

Since Jan 16Pushed 5y ago4 watchersCompare

[ Source](https://github.com/rapidwebltd/php-postcodes)[ Packagist](https://packagist.org/packages/rapidwebltd/php-postcodes)[ Docs](https://github.com/rapidwebltd/php-postcodes)[ RSS](/packages/rapidwebltd-php-postcodes/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (5)Versions (13)Used By (0)

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

[](#php-postcodes)

[![Build Status](https://camo.githubusercontent.com/b7dd646d0e05632a53a58f997c3692faae46679201c35fb72d1f878ea01becd2/68747470733a2f2f7472617669732d63692e6f72672f72617069647765626c74642f7068702d706f7374636f6465732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/rapidwebltd/php-postcodes)[![Coverage Status](https://camo.githubusercontent.com/1c47e83b70f15adc96818c7874a241619fa8fed1e2b4381fdea6367174dd1ab4/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f72617069647765626c74642f7068702d706f7374636f6465732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/rapidwebltd/php-postcodes?branch=master)[![StyleCI](https://camo.githubusercontent.com/6b7321f47de818fe8d8f8c7521d99598120e2d1e97cfbffaf9d094770f244bf4/68747470733a2f2f7374796c6563692e696f2f7265706f732f37393131353736382f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/79115768)[![Packagist](https://camo.githubusercontent.com/a28c2c4e365ab15b29b89c96e55447354383f6d0be6212a688c3e66f8b48e621/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72617069647765626c74642f7068702d706f7374636f6465732e737667)](https://camo.githubusercontent.com/a28c2c4e365ab15b29b89c96e55447354383f6d0be6212a688c3e66f8b48e621/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72617069647765626c74642f7068702d706f7374636f6465732e737667)

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 rapidwebltd/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) -

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 \RapidWeb\Postcodes\Objects\IdealPostcodes('API_KEY');
// OR
$postcodeLookupService = new \RapidWeb\Postcodes\Objects\PostcodeAnywhere('API_KEY');
```

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 = \RapidWeb\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 = \RapidWeb\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 = \RapidWeb\Postcodes\Utils\Tokenizer::outward('ST163JR'); // Returns ST16
$inwardCode = \RapidWeb\Postcodes\Utils\Tokenizer::inward('ST163JR'); // Returns 3JR
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 85.7% 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 ~41 days

Recently: every ~57 days

Total

12

Last Release

2951d ago

Major Versions

v1.2.1 → v2.0.02017-06-22

### 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 (12 commits)")[![kirsty-gasston](https://avatars.githubusercontent.com/u/12949343?v=4)](https://github.com/kirsty-gasston "kirsty-gasston (2 commits)")

---

Tags

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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