PHP code example of altrozero / postcode-uk

1. Go to this page and download the library: Download altrozero/postcode-uk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

altrozero / postcode-uk example snippets




$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



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



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



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