W
W
WebDev2015-08-10 10:28:44
PHP
WebDev, 2015-08-10 10:28:44

How to get the original link from twitter?

On twitter, all links look like t.co. Is it possible to get the original link programmatically? That is, follow it and find out where it redirects?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan GiBSON, 2015-08-10
@kirill-93

$url = 't.co/MCmDluFvEU';

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$html = curl_exec($ch);
curl_close($ch);

preg_match('/replace\(\"(.*)\"\)/i', $html, $matches);
$link = '';
if(isset($matches[1])){
  $link = stripcslashes($matches[1]);
}

Something like this, and then to your taste, but the php_curl extension must be installed

V
Vladislav Gaiduk, 2015-08-10
@Danan

$url = ' t.co ';
print_r(get_headers($url, 1));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question