When working on a project I found that I needed a simple solution that would allow me to expand or unshorten a short URL. I'm sure you know what short URL's look like: http://bit.ly/mwyBzI Anyway, there are several ways to do this. My first attempt was to accomplish this using jQuery. I used a jQuery library that called an API service. I ended up having to edit the jQuery plug-in to work the way that I wanted it to work. Anyway, it was not as simple as I had wished. After digging around for a little bit longer I found that there was a much simpler way to do this in PHP. Anyway, the solution and download is below:

You can easily accomplish the same result, by using the following PHP function:

function expandShortUrl($url) {

	$headers = get_headers($url,1);
	if (!empty($headers['Location'])) 
		$headers['Location'] = (array) $headers['Location'];
		$url = array_pop($headers['Location']);
	return $url;

Additionally, you can download the code here:


Hope this helps someone out ;)