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.

I had a big problem getting WordPress’s new-fandangled flash image uploader working on my Mac; the flash uploader button wouldn’t appear and I always saw the standard single image uploader button.

After a bit of research using the Safari Develop menu, I found that using a Windows user agent made it appear, and a Mac user agent would hide it.

After a quick delve into WordPress’s code I found this in /wp-admin/includes/media.php, lines 769-772…
769: // If Mac and mod_security, no Flash.
770: $flash = true;
771: if ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), ‘mac’) && apache_mod_loaded(’mod_security’) )
772:     $flash = false;

…which turns off the flash uploader if you’re using a Mac and your website runs Apache and has the mod_security module loaded… mine does!

So, commenting out the bottom two lines…
769: // If Mac and mod_security, no Flash.
770: $flash = true;
771: // if ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), ‘mac’) && apache_mod_loaded(’mod_security’) )
772: //     $flash = false;

…now forces WordPress to show the flash uploader regardless.

Hurrah :)

Valid XHTML 1.1 Valid CSS