Skip to content

Instantly share code, notes, and snippets.

@rthrash
Created August 15, 2010 13:49
Show Gist options
  • Save rthrash/525506 to your computer and use it in GitHub Desktop.
Save rthrash/525506 to your computer and use it in GitHub Desktop.
<?php
$link = urlencode($link);
//return getSmallLink($link);
//function getSmallLink($longurl){
// Bit.ly
$url = "http://api.bit.ly/v3/shorten?login=YOUR_LOGIN&apiKey=YOUR_API_KEY&longUrl=$link&format=txt&history=1";
$s = curl_init();
curl_setopt($s,CURLOPT_URL, $url);
curl_setopt($s,CURLOPT_HEADER,false);
curl_setopt($s,CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($s);
curl_close( $s );
// swap to a j.mp domain
$jmp = substr($result, 13);
return (!$urlencode) ? 'http://j.mp'.$jmp : urlencode('http://j.mp'.$jmp);
// for JSON
//$obj = json_decode($result, true);
//return $obj["results"]["$longurl"]["shortUrl"];
//}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment