Note:
function bitly($url,&$title) { $login="mylogin"; $apikey="my-api-key"; $bitlyurl="http://api.bit.ly/v3/expand?shortUrl=".urlencode($url)."&login=$login&apiKey=$apikey&format=json"; $inf=json_decode(simpleget($bitlyurl),true); $code=$inf["status_code"]; if($code != 200) { print "bitly($url) Error code $code\n"; return; } $ret=$inf["data"]["expand"][0]["long_url"]; $bitlyurl="http://api.bit.ly/v3/info?shortUrl=".urlencode($url)."&login=$login&apiKey=$apikey&format=json"; $inf=json_decode(simpleget($bitlyurl),true); $code=$inf["status_code"]; if($code != 200) { print "bitly($url) Error code $code\n"; return; } $title=$inf["data"]["info"][0]["title"]; print "bitly($url) title=$title ; url=$ret\n"; return $ret; } function simpleget($url) { $ch=curl_init($url); curl_setopt($ch, CURLOPT_TIMEOUT, 6); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_USERAGENT, "simpleget"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); return curl_exec($ch); }