On Jul 8, 2:26 pm, Stuart <stut...@gmail.com> wrote:
> 2009/7/8 AlexanderZn <alexan...@liljengard.se>:
>
>
>
>
>
> > Hi all!
>
> > I'm writing a twitter-widgets that is based on data formated as JSON.
> > I get the data from
> >http://twitter.com/statuses/user_timeline.json?screen_name=username
>
> > Locally this works like a charm, but when i upload the script to my
> > webserver i get negative ids.
>
> >            [id] => -1766397267
> > instead of,
> >            [id] => 2528570029
>
> > I get the data with file_get_contents() and turn it into an array with
> > json_decode($jsondata,true) with php..
>
> > Does anybody have a clue why it is like this?
>
> You're running on 32-bits and json_decode treats numbers it gets as
> numbers, so when converted to a signed 32-bit int it becomes negative.
>
> The easiest solution is to use the pear package Services_JSON instead
> of json_decode and ensure your code never treats the ID as a number.
> The better solution is to move to 64-bit but obviously that may
> involve changing hardware so might not be feasible for you.
>
> -Stuart
>
> --http://stut.net/projects/twitter/

Thanks!

Solved my problem. Since im planning on releasing my widget to the
public i would like it to work on most of the systems..
My solution was easy.
I just added a preg_replace and converted the int to a string:

preg_replace('#"id"\:([0-9]+)#i','"id":"$1"',file_get_contents($url))

Thanks for the pointer!

/ Alex

Reply via email to