PHP Class To Interact With is.gd API

The is.gd URL shortening service is yet another site that converts a long URL into a small one, but is.gd differs in that it generally produces smaller URLs than others. The is.gd API doesn't require that you create an account on the site, but there are one or two limitations to using the service that you should be aware of first. You can find out these limitations by reading the is.gd terms and conditions. You can use this class to interact with is.gd, but the service doesn't have a massive amount of features the class only contains shorten() and expand() functions that work exactly as expected. You can download the class using the following link:

Download the is.gd API interaction PHP class.

To convert a URL into its is.gd equivalent you can call the shorten() function like this.

include('isgd.php');
$isgd = new Isgd();
echo $isgd ->shorten('http://www.hashbangcode.com/');

This will return http://is.gd/1RfAA.

To convert a is.gd URL back to the original equivalent you can call the expand() function like this.

include('isgd.php');
$isgd = new Isgd();
echo $isgd->expand('http://is.gd/1RfAA');

This will return the original URL, or http://www.hashbangcode.com/ in this case.

The is.gd service also has a couple of extra features that allow you to either preview the URL before going to it, or to add some keywords to the URL. The only thing that you should be aware of is that you can't do both of these actions at the same time.

To create a is.gd preview URL use the following code.

include('isgd.php');
$isgd = new Isgd();
echo $isgd ->shorten('http://www.hashbangcode.com/', true);

This will return http://is.gd/1RfAA-, which is is.gd's way of moving you to a preview page so that you can see what the link is before clicking on it.

To add some keywords to your is.gd URL use the following code. Note that you must use false as the preview parameter if you want to do this. This is because the is.gd service can't do both previewing and keywords in the URL and the preview parameter will take precedence over the keyword parameter.

include('isgd.php');
$isgd = new Isgd();
echo $isgd ->shorten('http://www.hashbangcode.com/', false, 'hash/bang-code');

This will return the following URL.

http://is.gd/1RfAA/hash/bang-code

Note that the string you pass as the keyword is "slugged" before being used in the is.gd URL. This means that only alphanumeric characters are used and any spaces are converted to hyphens. is.gd ignores anything after the trailing hyphen so you can include any text you want, it doesn't even have to be the same for different URLs.

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
5 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.