Jump to content

String manipultaion


UHTMilk

Recommended Posts

Hiya there,

I have another newbie question for you good people out there. It's to do with splitting UK postcodes. I've got some of it worked out but wonder if you could lend any further advice. So far I've got: -

[code]
// Validate with this
if(!ereg("[A-Z]{1,2}[0-9][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{1,2}", strtoupper($postcode))) {
}

// Get outbound section with this
$outpc=explode(" ",$dat['postcode']);
$outbound=$outpc[1]
[/code]

I need to end up with three varaibles; the full code (rh1 1nn), the outbound code (rh1), and the area code from the outbound (rh). The first two were easy but I don't know of a way to get the third. As uk postcodes can be both 1 and 2 a-z characters before the number. So I don't know if there is anyway to extract from the string up to the first number.

I'd be grateful for any advice you could lend or maybe even a cleaner way of finding all three.

Thanks in advance,
Milk.
Link to comment
Share on other sites

[!--quoteo(post=354268:date=Mar 12 2006, 07:47 PM:name=UHTMilk)--][div class=\'quotetop\']QUOTE(UHTMilk @ Mar 12 2006, 07:47 PM) [snapback]354268[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hiya there,

I have another newbie question for you good people out there. It's to do with splitting UK postcodes. I've got some of it worked out but wonder if you could lend any further advice. So far I've got: -

[code]
// Validate with this
if(!ereg("[A-Z]{1,2}[0-9][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{1,2}", strtoupper($postcode))) {
}

// Get outbound section with this
$outpc=explode(" ",$dat['postcode']);
$outbound=$outpc[1]
[/code]

I need to end up with three varaibles; the full code (rh1 1nn), the outbound code (rh1), and the area code from the outbound (rh). The first two were easy but I don't know of a way to get the third. As uk postcodes can be both 1 and 2 a-z characters before the number. So I don't know if there is anyway to extract from the string up to the first number.

I'd be grateful for any advice you could lend or maybe even a cleaner way of finding all three.

Thanks in advance,
Milk.
[/quote]


Notice how in the strtoupper you are using $postcode, while in the explode statement you're using $dat['postcode'] .. i don't know the rest of your code, but that seems like it would be something to look in to.
Link to comment
Share on other sites

[!--quoteo(post=354276:date=Mar 12 2006, 08:05 PM:name=keeB)--][div class=\'quotetop\']QUOTE(keeB @ Mar 12 2006, 08:05 PM) [snapback]354276[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Notice how in the strtoupper you are using $postcode, while in the explode statement you're using $dat['postcode'] .. i don't know the rest of your code, but that seems like it would be something to look in to.
[/quote]

Hiya,

Thanks for getting back to me. The first one is validating from a form. The second example I used is where I'm pulling it from the db to compare. So it's no problems, but thanks for taking the time to look over it.

Milk.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.