I recently had a problem using PHP’s json_decode() with Twitter’s search API. The Twitpocalypse meant that the tweet status ids were being limited to 2147483647, and in my case, any new tweets weren’t being saved as the app thought they already existed.

To get around the problem of json_decode() limiting ints, I added a regex replace to change large numbers to strings by adding quote marks around them. json_decode() then sees the number as a string and parses it correctly.

An example search function with the fix is shown below:

function TwitterSearch($query) {
  $search_url = 'http://search.twitter.com/search.json?q='.$query;
  $ch = curl_init($search_url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  $json = curl_exec($ch);
   
  // -- int-max fix - convert number to string
  $json = ereg_replace('([:])([0-9]{10})([,}])', '\\1"\\2"\\3', $json);
   
  $result = json_decode($json);
  curl_close($ch);
  return $result;
}

The regex here only looks for 10-digit numbers, but this can easily be changed for larger numbers by changing the {10} to say {10,16} to catch 10 to 16 digit numbers.

Under construction…

15 June 2009

I’ve been collecting ideas and designs now for a while, with the intention of overhauling my blog - I have a feeling this design is nearly 6 years old.

I’m going to include the usual bits but there will be a social interaction theme to it too :)

If I had a nasty 90’s animated ‘Under construction’ gif, I’d add it… but thankfully I don’t.

I recently installed Trac to replace a crawling WebSVN install, and wanted to keep the modified files diff links generated on the CCNet build report.

To enable this I changed the webUrlBuilder Url to…

<project name="MyProject.Trunk.Continuous">
  ...
  <sourcecontrol type="svn">
    ...
    <webUrlBuilder type="websvn">
      <url>http://trac.myserver.com/MyProject/changeset/{1}{0}</url>
    </webUrlBuilder>
  </sourcecontrol>
  ...
</project>

…which now matches the url required to show file differences in Trac.

I’d never heard this until I listened to John Mayer’s Where The Light Is album on Spotify. Loving the tuning and the harmonics!

Smile!

06 March 2009

smiliesSpotted these in John Lewis last weekend :D