What is the best way in PHP or JS to expand shortened URLs like Bitly, Tinyurl to find the original URL?
问题 I am using the Twitter and Facewbook API to pull posts that potentially contain shortened URLs using bit.ly or TinyURL like services. I need to do a real-time expansion to get the original URL then pull content from that URL into my app. 回答1: You can use CURL to expand a short URL. Try this: function traceUrl($url, $hops = 0) { if ($hops == MAX_URL_HOPS) { throw new Exception('TOO_MANY_HOPS'); } $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1);