Skip to content

Instantly share code, notes, and snippets.

@rogerbuecker-snippets
Created October 12, 2012 11:45
Show Gist options
  • Save rogerbuecker-snippets/3878836 to your computer and use it in GitHub Desktop.
Save rogerbuecker-snippets/3878836 to your computer and use it in GitHub Desktop.
PHP: Short URL with Bit.ly
function get_short_link($url)
{
$bitly_login="yourloginname";
$bitly_apikey="yourapikey";
$api_call = file_get_contents("http://api.bit.ly/shorten?version=2.0.1&longUrl=".$url."&login=".$bitly_login."&apiKey=".$bitly_apikey);
$bitlyinfo=json_decode(utf8_encode($api_call),true);
if ($bitlyinfo['errorCode']==0)
{
return $bitlyinfo['results'][urldecode($url)]['shortUrl'];
}
else
{
return false;
}
}
//Usage: get_short_link("http://snipt.net");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment