altrozero/postcode-uk

UK Postcode helper function

1.1 2019-05-07 15:25 UTC

This package is auto-updated.

Last update: 2024-05-09 11:31:25 UTC


README

codecov

UK Postcode Helper

PHP Helper class for dealing with UK postcodes.

Used to break postcodes in to parts based on

https://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Formatting

How to use

Break in to parts

<?php

$postcode = new Postcode('SR5 1NA');

$postcode->get(); // SR51NA
$postcode->getOutward(); //SR5
$postcode->getInward(); // 1NA
$postcode->getArea(); // SR
$postcode->getDistrict(); // 5
$postcode->getSector(); // 1
$postcode->getUnit(); // NA

Validate a postcode

<?php

$good = Postcode::validate('SR5 1nA'); // true
$bad = Postcode::validate('SR5 N1A'); // false

Format Postcodes in a consistent way

<?php

$formatted = Postcode::format('Sr51NA'); // SR51NA
$formatted = Postcode::format('sR5 1NA'); // SR51NA

Pull a postcode from an address string

<?php

$postcode = Postcode::findInString('1 Fake Street, Fake Vil, Fake Country, SR51NA');