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

Sponsors

isgdlogo

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 />';

?>

You may like following Articles!

This entry was posted in news, Open source, PHP, twitter and tagged , , by Wordpress API. Bookmark the permalink.

About Wordpress API

API means Application Program interface. In Wordpress API we are giving all the information about wordpress API. We worked for many wordpress plugins and themes. We have expertise in PHP, Databases, Graphic Design, Ruby on Rails, Java, Wordpress, Drupal and many CMS. We always give you the best solutions about wordpress and other related topics in This Blog. We will give you always fresh tips and tricks and techniques about wordpress in this blog.

One thought on “How to get Short Url from is.gd, api.tr.im, hex.io using PHP API

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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>