Decoding twitter tinyurl to get actula one


#1

I want to get actual URL from tinyurls. I got this script:

<?php
$url = "http://t.co/vpDXYaXl7m";
$full = URLDecode($url);
echo "URL is $full";
function URLDecode($url) 
{
    $ch = @curl_init($url);
    @curl_setopt($ch, CURLOPT_HEADER, TRUE);
    @curl_setopt($ch, CURLOPT_NOBODY, TRUE);
    @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
    @curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $url_resp = @curl_exec($ch);
    preg_match('/Location: (.*)\n/', $url_resp, $i);
    if (!isset($i[1]))
    {
        return $url;
    }
    return $i[1];
}
?>

But it does not respond. Is there any API or other solution for this?

UPDATE:

fortunately got this link:

http://api.longurl.org/v2/expand?url=http://t.co/vpDXYaXl7m

which gives long URL in xml form. But I am working in PHP and in backend I want to convert it to actual long URL


#2

okay, issue solved.

Above code works fine now. Please enable CURL in your system


#3