extracting part of postcode

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

extracting part of postcode

Post by gurjit »

ok its been a hard week, this ones easy but i just cant think properly

i have a database of postcodes

WV11 3QS
AB12 8EB
W1 7YY

I want to echo the first part of the character, so for the above examples

WV
AB
W
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: extracting part of postcode

Post by jaoudestudios »

You can do it various ways.

Just off the top of my head.
Explode on the white space then take the first part of the array and go through it character at a time and keep appending the result until a number is reached.

You could use a regular expression, if you wanted to be fancy.
Post Reply