Skip to content

Instantly share code, notes, and snippets.

@kikegarcia
Created July 25, 2013 13:57
Show Gist options
  • Save kikegarcia/6079910 to your computer and use it in GitHub Desktop.
Save kikegarcia/6079910 to your computer and use it in GitHub Desktop.
Bitly class
$url = 'http://toysessions.savethechildren.es/video/'.$data['urlname'];
$login = '';
$appkey = '';
$format = 'xml';
$version = '2.0.1';
$bitly = 'http://api.bit.ly/shorten?version='.$version.'&longUrl='.urlencode($url).'&login='.$login.'&apiKey='.$appkey.'&format='.$format;
$response = file_get_contents($bitly);
if(strtolower($format) == 'json')
{
$json = @json_decode($response,true);
//echo($json['results'][$url]['shortUrl']);
}
else //xml
{
$xml = simplexml_load_string($response);
$bitly = 'http://bit.ly/'.$xml->results->nodeKeyVal->hash;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment