Create short links using bit.ly from php
bit.ly is a simple url shortner which has an api , which can be called from within php to shorten links.
Code :
function get_short_url($url)
{
$bitly_login = "your_login_name";
$bitly_apikey = "your_api_key";
$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;
}
}