Skip to content

Instantly share code, notes, and snippets.

@alancoleman
Last active December 18, 2015 19:19
Show Gist options
  • Save alancoleman/5831765 to your computer and use it in GitHub Desktop.
Save alancoleman/5831765 to your computer and use it in GitHub Desktop.
Isolate just the area identifier from a UK postcode. So 'BA6 5TY' would result in 'BA' and 'N5 7TY' would result in 'N'
<?php
// Define postcode
$postcode = "BA6 5TY";
// Isolate first two characters of the postcode and replace any integer with nothing
$postcode_area = preg_replace("/[0-9]/","",substr($postcode, 0, 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment