1

Possible Duplicate:
Handling big user IDs returned by FQL in PHP

I have a JSON response from twitter api, I need to store tweets ids in database using php. The problem is that the tweet id has about 18 digits and php is reading in X.XXE+XX format. I'm on 32bit os. I tried this way with no success

$json = json_decode(file_get_contents($urlo, "r"));
foreach($json->results as $key){
$I_WANT_A_STRING = strval($key->id);
}

I would really appreciate any suggestion!

SOLVED thanks for suggestions, but when setting the parameters into the json_decode function it gave me other errors. If somebody get stuck with the same problem, in json response, every tweet has id and id_str attribute.

Community
  • 1
  • 1
lelloman
  • 13,883
  • 5
  • 63
  • 85
  • 4
    32bit PHP has a 32bit limit for ints. You cannot get around this, other than by using floats and losing precision. You could try using the BCMath library, but I don't think you can use it in this case, because you'd first have to decode the json into an intermediate PHP value BEFORE feeding it to bcmath, which will mangle the value anyways. – Marc B Dec 14 '12 at 16:04
  • http://stackoverflow.com/a/2928422/362536 – Brad Dec 14 '12 at 16:04
  • 1
    use the `JSON_BIGINT_AS_STRING` option to [`json_decode`](http://php.net/manual/en/function.json-decode.php) – didierc Dec 14 '12 at 16:06

0 Answers0