How to get Short Url from using PHP API WITH is.gd, api.tr.im, hex.io

Creating the short url is now becoming the popular trend because of twitter and facebook. Tutorial about How to get Short Url from using PHP API WITH is.gd, api.tr.im, hex.io.

 

get Short Url from using PHP
get Short Url from using PHP

If you want to use API in php for creating the short URL. use following code:


<?php //Get short URL from free API with purabtech.in/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.purabtech.in/'); echo $short_url; ?>

<br>

Sample ofHow to Use<br><br>


<?php
$long_url = 'http://images.purabtech.in/';
$short_url = get_short_url($long_url,'hexio');
echo $short_url;
echo '
';
$short_url = get_short_url($long_url,'isgd');
echo $short_url;
echo '
';
$short_url = get_short_url($long_url,'trim');
echo $short_url;
echo '
';

?>