in php5, how to stop GET from (wrongly) converting into numeric?
Question
in relation to php int64 limits, if the uri has a int64 argument, how do you prevent GET from wrongly converting it into numeric and simply keeping it as a string?
http://some.com?id=1707541557936130
then
echo $_GET['id'] => 1.7075415579361E+15
how to prevent this and have $_GET['id']
be the string 1707541557936130
?
the way $_GET
works now is unusable. need to parse $_SERVER["QUERY_STRING"]
myself. but then never know when php will grab a variable and incorrectly convert again.
NOTE: afaik this will be a problem on 32bit, not 64bit php installs.
Solution 3
bite the bullet and install 64bit - it's what's on your server anyway
OTHER TIPS
Everyrthing coming out of _GET/_POST/_COOKIE is a string. That data wouldn't be converted to a number unless you did something that forced it to be interpreted as one.
echo $_GET['id']; // echoes your big number
echo $_GET['id'] + 0; // forces an int conversion
This should get the job done.
echo (string) $_GET['id'];
If the current solutions are not working you can append a string character to the integer such as
http://some.com?id=i1707541557936130
Additionally, if it is an issue of how the float is displayed you can use number_format().
$id = (string) number_format($_GET['id']);
echo $id;