Created
September 7, 2013 15:43
-
-
Save bjrnqprs/6476662 to your computer and use it in GitHub Desktop.
A simple function to resolve a shortened url to its original. Uses PHP+cURL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env php | |
<?php | |
// Resolve Short URL | |
function resolveShortURL($url) { | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_HEADER, false); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_NOBODY, true); | |
$yy = curl_exec($ch); | |
$endUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); | |
curl_close($ch); | |
return $endUrl; | |
} | |
if($argc === 2) { | |
echo resolveShortURL($argv[1])."\n"; | |
} else { | |
echo "ERROR: Missing first parameter: URL.\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment