Find the True URL of Something, Following Redirects

Have you ever wanted to know the definitive URL to something on the Internet, following any 301 redirects?  I am working on a podcast-related site right now, and recently had to keep track of a multitide of podcast URL's, even when they change.  The following PHP code saved the day:

function get_final_url($url) {
  $ch = curl_init($url);
  $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
  return $url;

To use, let's say you have a url of ""  but, unbeknownst to you, that URL actually has a 301 redirect to "". 

You can use the function this way:

$url = get_final_url("");

And $url will now contain "".