Skip to content

Instantly share code, notes, and snippets.

@nckltcha
Created August 17, 2012 15:26
Show Gist options
  • Select an option

  • Save nckltcha/3379868 to your computer and use it in GitHub Desktop.

Select an option

Save nckltcha/3379868 to your computer and use it in GitHub Desktop.
bit.ly API PHP Shortener
<html>
<head>
</head>
<body>
<?php
function bitly($add)
{
$long_url = urlencode($add);
$bitly_login = 'LOGIN';
$bitly_apikey = 'APIKEY';
$bitly_response = json_decode(file_get_contents("http://api.bit.ly/v3/shorten?login={$bitly_login}&apiKey={$bitly_apikey}&longUrl={$long_url}&format=json"));
$short_url = $bitly_response->data->url;
echo $short_url;
}
echo "ShortUrl: ";
bitly('http://www.google.co.uk');
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment