Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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