PHP Classes
elePHPant
Icontem

PHP Royal Mail Barcode Checksum Generator: Generate checksum digits for a Royal mail postcode

Recommend this page to a friend!
  Info   View files Example   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2015-06-24 (4 years ago) RSS 2.0 feedNot yet rated by the usersTotal: 78 All time: 9,393 This week: 298Up
Version License PHP version Categories
post-code-checksum 1.0GNU General Publi...5.3Algorithms, PHP 5, Geography
Description Author
This package is specific mainly for applications used in United Kingdom United Kingdom .

This class can generate checksum digits for a Royal mail postcode.

It takes a postcode string and processes to compute its checksum as defined in the OnePost Royal Mail manual Appendix H: Using Customer Barcode CBC.

The computed checksum is returned as a single digit or letter value.

Innovation Award
PHP Programming Innovation award nominee
July 2015
Number 9
Royal Mail is the postal service of the United Kingdom. They adopted a barcode system for their Cleanmail service.

The barcode is based on the postal code of a given address. It uses an algorithm to compute a checksum and prevent mistakes when typing the postal code.

This class can compute the Royal Mail Barcode checksum for a given postal code using pure PHP code.

Manuel Lemos
  Performance   Level  
Name: Ciaran Moore <contact>
Classes: 5 packages by
Country: United Kingdom United Kingdom
Age: 33
All time rank: 2414109 in United Kingdom United Kingdom
Week rank: 108 Up4 in United Kingdom United Kingdom Up
Innovation award
Innovation award
Nominee: 1x

 

Details

Royal Mail Barcode Checksum Generator

A PHP Class to Generate a Royal Mail Barcode Checksum, as outlined in [this] guide.

Details on what this requires are as follows;

6.5. Checksum character

If you don?t use proprietary software from PIF or a Royal Mail approved co-supplier then

you?ll need to work out the checksum character yourself.

This involves using an algorithm, as described below. The checksum character is used as a

means of error detection to ensure that the rest of the barcode is correct.

*Working out the checksum character*

Checksum characters can be automatically produced through the software available from

co-suppliers. They are also available on the PIF®. They can however also be calculated by

following these steps:

Step one

Use the table to find row and column references for the characters in the Postcode and DPS.

Note that the sixth row/column is numbered 0 not

| | 1 | 2 | 3 | 4 | 5 | 0 | |-------|-----|-----|-----|-----|-----|-----| | 1 | 0 | 1 | 2 | 3 | 4 | 5 | | 2 | 6 | 7 | 8 | 9 | A | B | | 3 | C | D | E | F | G | H | | 4 | I | J | K | L | M | N | | 5 | O | P | Q | R | S | T | | 0 | U | V | W | X | Y | Z |

For example the letter S is in row 5 and column 5. Write these down in a grid like this (we?ve

used an example Postcode of SN3 4RD and DPS of 1A), then add them up:

|Postcode and DPS | S | N | 3 | 4 | R | D | 1 | A | Total | |-----------------:|---|---|---|---|---|---|---|---|:--------:| | Row | 5 | 4 | 1 | 1 | 5 | 3 | 1 | 2 | 22 | | Column | 5 | 0 | 4 | 5 | 4 | 2 | 2 | 5 | 27 |

Step two

Divide the totals by six (it is always six, no matter how many characters are in the Postcode),

and note the amount left over. In this example:

goes into 22 three times with 4 left over

6 goes into 27 four times with 3 left over

Step three

Refer these ?left over? figures back to the table, finding the character where they intersect.

For example, row 4 and column 3 gives the checksum character K.

Even if your ?left over? character is zero (i.e. 6 into 24 goes four times with zero left over), this

will relate to a row or column on the grid.

General Usage Instructions

In order to use the class. Simply include the file, and create an instance of it in your application.

Then call the ProcessPostcode() Function with the Post Code you require the checksum for.

i.e.

*$chk = new PostCodeCheckSum();*

*$checksum = $chk-&gt;ProcessPostcode(?MK1 1ST?);*

[this]: http://onepost.co.uk/wp-content/uploads/2013/03/OP-RM-Appendix-H.pdf

  Files folder image Files  
File Role Description
Files folder imagetest (1 file, 1 directory)
Plain text file LICENSE Lic. Auxiliary data
Plain text file PostCodeCheckSum.php Class Class source
Plain text file README.md Doc. Auxiliary data

  Files folder image Files  /  test  
File Role Description
Files folder imagelib (1 directory)
  Plain text file testPostcodeChecksum.php Example Example script

  Files folder image Files  /  test  /  lib  
File Role Description
Files folder imageclasses (1 file)

  Files folder image Files  /  test  /  lib  /  classes  
File Role Description
  Plain text file PostCodeCheckSum.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:78
This week:0
All time:9,393
This week:298Up