Reputation: 41
I am reading in a CSV file (in UTF-8 encoding). One of the values is a number and when I try to cast it as an integer so I can do some calculations it is just being set to zero. What am I doing wrong?
var_dump ( $row3[_MM_Impressions] );
//writes: string(5) "59"
$imps = (int)$row3[_MM_Impressions];
var_dump($imps);
//writes: int(0)
$imps = $row3[_MM_Impressions]*1;
var_dump($imps);
//writes: int(0)
$imps = intval($row3[_MM_Impressions]);
var_dump($imps);
//writes: int(0)
Upvotes: 2
Views: 69
Reputation: 223
You have HEX string number in your vars... so why don't you use hexdec?
Returns the decimal equivalent of the hexadecimal number represented by the hex_string argument. hexdec() converts a hexadecimal string to a decimal number.
hexdec() will ignore any non-hexadecimal characters it encounters.
Upvotes: 2