Creating the short url is now becoming the popular trend because of twitter and facebook.
If you want to use API in php for creating the short URL. use following code:
<?php
//Get short URL from free API with wordpressapi.com/files/
function get_short_url($long_url,$provider='isgd') {
$ch = curl_init();
$timeout = 5;
switch(strtolower(trim($provider))) {
case "isgd":
curl_setopt($ch,CURLOPT_URL,'http://is.gd/api.php?longurl='.$long_url);
break;
case "hexio":
curl_setopt($ch,CURLOPT_URL,'http://hex.io/api-create.php?url='.$long_url);
break;
case "trim":
$return = "http://api.tr.im/v1/trim_url.xml?url=%s";
curl_setopt($ch,CURLOPT_URL,'http://api.tr.im/v1/trim_url.xml?url='.$long_url);
break;
default:
curl_setopt($ch,CURLOPT_URL,'http://is.gd/api.php?longurl='.$long_url);
}
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$content = curl_exec($ch);
curl_close($ch);
// return the short URL
return $content;
}
//uage
$short_url = get_short_url('http://images.wordpressapi.com/');
echo $short_url;
?>
<br>
Sample ofHow to Use<br><br>
<?php $long_url = 'http://images.wordpressapi.com/'; $short_url = get_short_url($long_url,'hexio'); echo $short_url; echo '<br />'; $short_url = get_short_url($long_url,'isgd'); echo $short_url; echo '<br />'; $short_url = get_short_url($long_url,'trim'); echo $short_url; echo '<br />'; ?>







Pingback: Tweets that mention How to get Short Url from is.gd, api.tr.im, hex.io using PHP API | wordpressapi.com -- Topsy.com