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

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

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.

v3.0.0(4w ago)03.3k4LGPL-3.0-onlyPHPPHP ^7.4 || ^8.0CI passing

Since Jan 16Pushed 4w 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 2w ago

READMEChangelog (10)Dependencies (9)Versions (14)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)[![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

54

—

FairBetter than 97% of packages

Maintenance94

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 87.5% 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 ~289 days

Recently: every ~772 days

Total

13

Last Release

29d ago

Major Versions

v1.2.1 → v2.0.02017-06-22

v2.2.0 → v3.0.02026-07-17

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

v3.0.0PHP ^7.4 || ^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 (14 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)
```

###  Alternatives

[sylius/sylius

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

8.5k6.0M777](/packages/sylius-sylius)[aedart/athenaeum

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

265.2k](/packages/aedart-athenaeum)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

353.6k](/packages/eslazarev-wildberries-sdk)[lion/bundle

Lion-framework configuration and initialization package

132.4k5](/packages/lion-bundle)

PHPackages © 2026

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