Yep, I did it again, I wrote a wrapper-class. This class communicates with TinyUrl.com. It is able to create short urls and reverse TinyUrls into the original link.
Go grab your copy: http://classes.verkoyen.eu/tinyurl.
The class is - like always - documentes in the file itself. So it should be easy to figure out how it works. But below you will find an example:
<?php
// require the class
require_once 'tinyurl.php';
// create instance
$tiny = new TinyUrl();
// create TinyUrl
echo $tiny->create('http://blog.verkoyen.eu/blog/p/detail/php-tinyurl-class-create-and-reverse'); // will output: http://tinyurl.com/klaofb
// reverse an existing TinyUrl
echo $tiny->reverse('http://tinyurl.com/aplvg'); // will output: http://crsolutions.be
?>
Reacties
David Geens schreef:
24/07/09
Spijtig dat het enkel werkt met TinyURL.com, die door hun succes soms redelijk traag antwoorden en anderzijds door hun naamkeuze momenteel één van de langere shortcutters zijn.
Misschien een leuke uitbreiding om ook http://is.gd mee op te nemen?
Tijs Verkoyen schreef:
24/07/09
Ik zal er eens over nadenken. Ik had deze class eigenlijk al ergens liggen. Heb ze opgekuist en gereleased.
Tijs Verkoyen schreef:
27/07/09
@David, het is bit.ly geworden. Die bied ook stats aan. zie: http://blog.verkoyen.eu/blog/p/detail/bit-ly-php-wrapper-class of http://bit.ly/10xN81 ;)