URL Shortening using PHP

Yesterday while developing PunBB Twitter extension, Invarbrass of Projanmo Forum helped me by providing some URL shortening snippets for several websites. Those were very simple to use. I am sharing so that it comes to others’ usages.

function CompressURL($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://to.ly/api.php?longurl=".urlencode($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$shorturl = curl_exec ($ch);
curl_close ($ch);
return $shorturl;
echo CompressURL("http://projanmo.com");

Continue reading →