TinyUrl class

__construct

Default constructor

Return

void

Example

<?php

// require the class
require_once 'tinyurl.php';

// create instance
$tinyUrl = new TinyUrl();

?>

setTimeOut

Set the timeout
After this time the request will stop. You should handle any errors triggered by this.

Parameters

seconds int
The timeout in seconds

Return

void

setUserAgent

Set the user-agent for you application
It will be appended to ours, the result will look like: "PHP TinyUrl/<version> <your-user-agent>"

Parameters

userAgent string
Your user-agent, it should look like <app-name>/<app-version>

Return

void

create

Create a TinyUrl

Parameters

url string
The orginal url that should be shortened

Return

string

Example

<?php

// require the class
require_once 'tinyurl.php';

// create instance
$tinyUrl = new TinyUrl();

// create a TinyUrl
echo $tinyUrl->create('http://blog.verkoyen.eu/blog/p/detail/php-tinyurl-class-create-and-reverse');

?>
Output
http://tinyurl.com/klaofb

reverse

Reverse a TinyUrl into a real url

Parameters

url string
The short tinyUrl that should be reversed

Return

mixed If something fails it will return false, otherwise the orginal url will be returned as a string

Example

<?php

// require the class
require_once 'tinyurl.php';

// create instance
$tinyUrl = new TinyUrl();

// reverse an existing TinyUrl
echo $tinyUrl->reverse('http://tinyurl.com/aplvg');

?>
Output
http://crsolutions.be

About me?

Well, I'm Tijs Verkoyen, a self employed Belgian PHP-developer at Sumo Coders.

If you want to know more about me, check my blog (Dutch).

If you really like my work and want to support me, feel free to use the donate-button below.

Spoon

At both companies, we use Spoon. Spoon is a PHP5 Library that we use for building all our Web 2.0 applications.

The classes that you can download from this website are standalone, so each developer is free to use a library/framework/… he likes best.