Shorten url services class V 1.0

This library will help you to easy use shorten url classes like tinyurl, bitly, goo.gl and others.

View a demo or Download the library

Initializing the Class

You can initialize the class in two ways:
$object = new Shorturl();

$object = new Shorturl('http://example.com/');

One you have create an object, you can configure some of the services. This is because services like Bit.ly require you to have an API KEY, an username or more parameters in order to work. Please read each function description in order to use the service.

Usage Example

This example demonstrates how to use a service of your choice

$url = 'http://www.example.com/';
$object = new Shorturl($url);
$bitly_apikey='12345678901' ; // this must be a valid apikey
$bitly_user = my_bitly_user; // this must be a valid bitly user

// using bitly
echo $object->bitly();

// using goo.gl
echo $this->shorturl>google();
You can use the methods in 2 ways, passing parameters o using the paramenters you already set as attibutes to the class.

 

Attributes Reference

Attribute Scope Type Description Example
url public string This is the main url you want to shorten  
bitly_username public string Your bit.ly username  
bitly_apikey public string Your bit.ly API key  
cligs_apiid public string Your cli.gs API id  
cligs_apikey public string Your cli.gs API key  
klam_apikey public string Your kl.am API key  



Methods Reference

$object->tinyurl()

Permits you to use the http://tinyurl.com service

$url = 'http://www.example.com/this_is_a_very_large/url_that_I_want_to_compress';

echo $object->tinyurl($url);

$object->cligs()

Permits you to use the http://cli.gs service

$object->url = 'http://www.example.com/this_is_a_very_large/url_that_I_want_to_compress';
$object->apikey='your_api_key';
$object->apiid='your_api_id';
$object->title='url_title';

echo $this->shorturl->cligs();

$object->cligs_expand()

Permits you to use the http://cli.gs service to expand an original cli.gs url

$object = url = 'http://cli.gs/UQdya9s';

echo $object->cligs_expand();

$object->klam()

Permits you to use the http://kl.am service

$object->url = 'http://www.example.com/this_is_a_very_large/url_that_I_want_to_compress';
$object->apikey='your_api_key';
$object->tags='first_tag+second_tag+more_tag';
$object->utm_source='My_web';

echo $object->klam();

Note: Only $url param is required, all other three are optional

$object->trim()

Permits you to use the http://tr.im service

$url = 'http://www.example.com/this_is_a_very_large/url_that_I_want_to_compress';

echo $object->trim($url);

$object->isgd()

Permits you to use the http://is.gd service

$url = 'http://www.example.com/this_is_a_very_large/url_that_I_want_to_compress';

echo $object->isgd($url);

$object->bitly()

Permits you to use the http://bit.ly service

$url = 'http://www.example.com/this_is_a_very_large/url_that_I_want_to_compress';
$bitly_apikey = 'your_api_key';
$bitly_username ='your_username';

echo $object>bitly();

$this->shorturl->bitly_expand()

Permits you to use the http://bit.ly service to expand an original bit.ly url

$url = 'http://bit.ly/9yiOuD';

echo $object->bitly_expand($url);

$this->shorturl->google()

Permits you to use the http://goo.gl service

$url = 'http://www.example.com/this_is_a_very_large/url_that_I_want_to_compress';

echo $object->google();