/ home / PHP / get an australian state from a postcode lookup /

Get an Australian State from a Postcode lookup

9:19 pm, July 28, 2016 320 190 1.0 @ 200 wpmrate up KruXoR
6

Here is a fairly (not exactly) accurate php function to get the australian state string from a postcode number range.

 

Usage:

echo get_state_au(2000); /* display the state code */
$state = get_state_au(2000); /* assign the state code to the variable $state. */

Code:

function get_state_au($postcode) {
$state = false;
if(!is_numeric($postcode)) { return false; }

if(($postcode >= 2000 && $postcode <= 2899)) { $state = "NSW"; } // nsw should be checked 1st as act may override it
if(($postcode >= 2600 && $postcode <= 2618)) { $state = "ACT"; }
if(($postcode >= 2900 && $postcode <= 2999)) { $state = "ACT"; }
if(($postcode >= 0800 && $postcode <= 0900)) { $state = "NT"; }
if(($postcode >= 4000 && $postcode <= 4999)) { $state = "QLD"; }
if(($postcode >= 5000 && $postcode <= 5999)) { $state = "SA"; }
if(($postcode >= 7000 && $postcode <= 7999)) { $state = "TAS"; }
if(($postcode >= 3000 && $postcode <= 3999)) { $state = "VIC"; }
if(($postcode >= 6000 && $postcode <= 6999)) { $state = "WA"; }

return $state;
}
9:19 pm, July 28, 2016 320 190

Comments

Reports

Add Report

Report's

KruXoR

This is a site where i basically just post whatever i feel like at the time, it has no one particular topic but usually. Just my ideas and links and random bits of code that i find.

Follow Me..

@KruXoR

Minecraft

Looking for the kruxor minecraft server mc.kruxor.com? we have migrated it to... icekraft.com if you want to play on there just connect to play.icekraft.com:25535 or mc.kruxor.com should also still work.

Favorite Links