During testing, a funny thing I found out. Seems related to the PHP version. On my work machine with php 5.3.3, the $item->results[0]->id is properly decoded using json_decode(). On my web machine with PHP 5.2.6, the bad X.yyyyE+Z format is used.
Output on work machine:
Code: Select all
REAL ID: 55187053255720960
SPRINTF ID: 55187053255720960
SPRINTF2 ID: 55187053255720960
STRING ID: 55187053255720960
STRVAL ID: 55187053255720960
(ID_STR): 55187053255720960
REAL ID: 55166449991421952
SPRINTF ID: 55166449991421952
SPRINTF2 ID: 55166449991421952
STRING ID: 55166449991421952
STRVAL ID: 55166449991421952
(ID_STR): 55166449991421952
Code: Select all
REAL ID: 5.51870532557E+16
SPRINTF ID: 55187053255720960
SPRINTF2 ID: 55187053255720960
STRING ID: 5.51870532557E+16
STRVAL ID: 5.51870532557E+16
(ID_STR): 55187053255720960
REAL ID: 5.51664499914E+16
SPRINTF ID: 55166449991421952
SPRINTF2 ID: 55166449991421952
STRING ID: 5.51664499914E+16
STRVAL ID: 5.51664499914E+16
(ID_STR): 55166449991421952
Code: Select all
<?php
$in = file_get_contents('http://search.twitter.com/search.json?q=http://tinyurl.com/3cbhcbx');
$item = json_decode($in);
$out = array();
foreach($item->results AS $result) {
echo "REAL ID: " . $result->id . "\n";
echo "SPRINTF ID: " . sprintf("%0.0f", $result->id) . "\n";
echo "SPRINTF2 ID: " . sprintf("%17.0f", $result->id) . "\n";
echo "STRING ID: " . (string)$result->id . "\n";
echo "STRVAL ID: " . strval($result->id) . "\n";
echo "(ID_STR): " . $result->id_str . "\n";
echo "\n";
}
(BTW: As you can see in my result, no "+1" is needed).