The PHP substr function does not accept strings converted from integers… 😛
The situation
If I leave the code like this, it works:
<?php
$key = '35110100840754000150550010000014301000000809';
echo substr($key, 35, -1);
?>
And the result is right:
00000080
The problem
But I get this key from an integer variable (from the database). So the result is null and similar to what I get from this code:
<?php
$key = 35110100840754000150550010000014301000000809;
echo substr($key, 35, -1);
?>
And the result is a blank string.
I tried everything, like (string) casting, substr($key.””, 35, -1) , and it does not work.
Does anyone have any suggestions?
If the database is returning an integer value, then it’s subject to the 32-bit (or 64-bit if you’re on a 64-bit server) limitations. 35110100840754000150550010000014301000000809 way exceeds the max integer value for even a 64-bit server.
It may be converted to a float, in which case you’ll be losing accuracy.
Get your database query to cast it as a string, and that should solve your problem