Postcode Matching
Posted: Tue May 10, 2016 3:24 pm
Hi All,
I am wanting abit of advice how to go about matching postcodes together to get a value. My issue is where I have single letter postcodes against double letter prefixes and both return true.
I am not trying anything too complicated regards having ranges etc I am having postcodes either by the first letter/s or full prefixes. To give you an idea I have a product page which once the postcode is entered it checks to see if the shipping zone for this product needs to add additional prices to the total. As we are dropshipping from 6 different areas of the UK so they all different in prices.
So I have postcodes outputting in a foreach loop to check against the postcode set in a cookie. So for example I have a postcode of E1 3EE and the stored postcodes and prices are :-
E - £5
EC - £10
NW - £10
LL15 - £10
LL16 - £10
LL17 - £10
I want to loop through and find the best matched so in this case it would be E but at the moment I am getting true from 2 E and EC.
I have tried str_split to match characters with each other but I think I am way overthinking this as I have been sat having ago at this for days. Has anyone done this before or can they give me a kick in the right direction?
Your thoughts advice would be greatly appreciated.
J
I am wanting abit of advice how to go about matching postcodes together to get a value. My issue is where I have single letter postcodes against double letter prefixes and both return true.
I am not trying anything too complicated regards having ranges etc I am having postcodes either by the first letter/s or full prefixes. To give you an idea I have a product page which once the postcode is entered it checks to see if the shipping zone for this product needs to add additional prices to the total. As we are dropshipping from 6 different areas of the UK so they all different in prices.
So I have postcodes outputting in a foreach loop to check against the postcode set in a cookie. So for example I have a postcode of E1 3EE and the stored postcodes and prices are :-
E - £5
EC - £10
NW - £10
LL15 - £10
LL16 - £10
LL17 - £10
I want to loop through and find the best matched so in this case it would be E but at the moment I am getting true from 2 E and EC.
I have tried str_split to match characters with each other but I think I am way overthinking this as I have been sat having ago at this for days. Has anyone done this before or can they give me a kick in the right direction?
Your thoughts advice would be greatly appreciated.
J