Bit.ly provides a URL shortening service, which comprises of a hash of the URL you provide. This produces a nice short URL which is unique and makes sharing across social bookmarking websites such as Stumbleupon and delicious easy.

First things first, you will need to register with Bit.ly for an API access key:

bit.ly, a simple url shortener

When you have your API username and key you can use the PHP script below to shorten all of your URL's.

PHP Code:
<?php
    
// Takes a url and shortens using the Bit.ly API
    // Usage: $short = new BitlyShorten("http://www.freewhosting.com", "yourapiusername", "yourapikey");

    
class BitlyShorten
    
{
        public 
$url$apikey$apiuser$bitly;
        
        public function 
__construct($iURL$iApiKey$iApiUser)
        {
            
$this->url urlencode($iURL);
            
$this->apikey $iApiKey;
            
$this->apiuser $iApiUser;
        }
        
        function 
GetShortenURL()
        {
            
$this->bitly 'http://api.bit.ly/shorten?version=2.0.1&longUrl='.$this->url.'&login='.$this->apiuser.'&apiKey='.$this->apikey.'&format=xml';
            
$response file_get_contents($this->bitly);
            
$xml simplexml_load_string($response);
            return 
urlencode('http://bit.ly/'.$xml->results->nodeKeyVal->hash);
        }
    }
?>
Happy shortening!