You could use get_headers()
or cURL
to grab the Location
header:
function getFullURL($url) {
$headers = get_headers($url);
$headers = array_reverse($headers);
foreach($headers as $header) {
if (strpos($header, 'Location: ') === FALSE) {
$url = str_replace('Location: ', '', $header);
break;
}
}
return $url;
}
Usage:
echo getFullURL('http://tinyurl.com/kmx9zt6');
Note: It's a slightly modified version of the gist here.