Created
August 15, 2010 13:49
-
-
Save rthrash/525506 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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