November 13, 2009

Generating a is.gd url using PHP

I was just adjusting a plugin on my blog, when I needed to shrink urls on the fly with is.gd.

function getShortUrl($url) {
$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'http://is.gd/api.php?longurl=' . $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3);
$ret = curl_exec($c);
curl_close($c);
return $ret;
}

Have fun generating those links.

Leave a Reply