I'm having trouble converting string to int. The array $input holds following values:
array(3) { [0]=> string(6) "30" [1]=> string(2) "01" [2]=> string(9) "2013" }
First I remove the leading zeros, because of the octa trap. So this is my code:
foreach ($input as $key => $var) {
$input[$key] = trim($var,"0");
$input[$key] = (int)$var;
}
But unfortunately the result is not statisfying.
array(3) { [0]=> int(0) [1]=> int(1) [2]=> int(2013) }
30 is now zero? How is this possible?
[0]=> string(6) "30"
This string has some non-printable characters in the beginning. It looks like 2 characters long, but in reality there are 6 of them. Such characters would cause the string to be converted to 0
as is documented.
You should try bin2hex
on the string to see what byte values we are talking about, then use this knowledge to determine where they come from.
The "2013"
string also has extra characters, although by the looks of it they are trailing in that case.