Converting string to number
It seems to be a very simple question, I use "0888" as my input value
example here. I have researched for a while and tried different ways, such
as
(int) "0888";
intval("0888");
floatval("0888");
settype("0888", "integer");
Unfortunately none of them seems to work. Reference 1 Reference 2 Reference 3
$num = $_POST['postcode'];
if((1000 <= $num && $num <= 1999) || (2000 <= $num && $num <= 2599) ||
(2619 <= $num && $num <= 2898) || (2921 <= $num && $num <= 2999)){
$state = "NSW";
}
elseif((0200 <= $num && $num <= 0299) || (2600 <= $num && $num <= 2618) ||
(2900 <= $num && $num <= 2920)){
$state = "ACT";
}
elseif((3000 <= $num && $num <= 3999) || (8000 <= $num && $num <= 8999)){
$state = "VIC";
}
elseif((4000 <= $num && $num <= 4999) || (9000 <= $num && $num <= 9999)){
$state = "QLD";
}
elseif((5000 <= $num && $num <= 5799) || (5800 <= $num && $num <= 5999)){
$state = "SA";
}
elseif((6000 <= $num && $num <= 6797) || (6800 <= $num && $num <= 6999)){
$state = "WA";
}
elseif((7000 <= $num && $num <= 7799) || (7800 <= $num && $num <= 7999)){
$state = "TAS";
}
elseif((0800 <= $num && $num <= 0899) || (0900 <= $num && $num <= 0999)){
$state = "NT";
}
else {
$state = "Can not find this postcode record";
}
If I echo $stateI expect to see NT but actually I see "Can not find this
postcode record" instead. Can anyone tell me what the problem is?
No comments:
Post a Comment