Posts Tagged ‘function’

Checking if the Twitter API is Up in PHP

Here’s a quick function that returns true if the Twitter API is up and responding, and false if otherwise:
function dieifnotup() {
$tw = curl_init();
curl_setopt($tw, CURLOPT_URL, "http://twitter.com/help/test.json");
curl_setopt($tw, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($tw, CURLOPT_TIMEOUT, 5);
$twi = curl_exec($tw);
curl_close($tw);
return (json_decode($twi) == "ok") [...]

PHP Function for Expanding Bit.ly Short URLs

Bit.ly is quickly becoming the defacto standard for URL shortening, and offers a pretty good API for developers. I was looking for a way to expand bit.ly short URLs to the original, long URLs they redirect to, and ended up writing this function:
// given a bit.ly url, passed in as $url, return the long form [...]