Giter Club home page Giter Club logo

php-postcodes's Introduction

PHP Postcodes

Build Status Coverage Status StyleCI Packagist

This library handles various UK postcode related tasks.

Features

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

Installation

To install, just run the following composer command.

composer require rapidwebltd/php-postcodes

Setup

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.

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

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

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

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

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

php-postcodes's People

Contributors

divineomega avatar kirsty-gasston avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

php-postcodes's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.