Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Rob Allen's Blog:
Validating UK Postcodes
Nov 15, 2010 @ 18:29:35

Rob Allen has shared a bit of code he's put together to help with validating UK postal codes (since the functionality in Zend_Validate doesn't cooperate), so he extended the main Zend_Validate_PostCode with his own validator.

It's easy enough to add a filter to remove the space, but I'm a little worried that when (and if) it gets fixed, will the fixed version Zend_Validate_PostCode then fail to validate postcodes without the space? In theory it should as the space is part of the spec. I'd hate my code to unexpectedly break due to a valid bug fix. I can easy work around this worry though by simply creating my own extension of Zend_Validate_PostCode.

The thirty-five line code example allows you to correctly validate the postal code with a quick call to the "isValid" method. He also links to another method from Paul Court to handle things similarly.

tagged: postcode uk validation zendframework zendvalidate

Link:

Derick Rethans' Blog:
PHP and Ordnance Survey Mapping
Apr 28, 2010 @ 15:55:14

Derick Rethans, indulging his "map geek" side, has written up a new post showing how he took the data from Ordnance Survey and mapped some information in the UK - postcode density for the whole area.

I decided to map all the postcodes onto the UK map where more postcodes for a specific place would create a "lighter" colour. Each postcode has on average about 15 addresses, so in more densely populated areas you have more "postcodes-per-area". Doing this wasn't very difficult and it resulted in the following map.

He walks through the entire process including how, in working with the data, he noticed alignment issues caused by the differing projections the map information service uses (Mercator) versus just mapping to a flat image. Some calculations were made to convert the latitude/longitude to the correct locations and the resulting points were plotted on a cut-out image of the UK.

After I figured out all the maths for this, the only problem that remains that implementing those algorithms in PHP is show—calculating all the positions from the 1.6 million postcode locations takes up to 10 minutes. This is why I am not presenting any code yet. I am planning to implement all the necessary calculations in a PHP extension to speed up the calculations.
tagged: ordnance survey mapping uk postcode

Link:


Trending Topics: