Show Posts
← Back to homepage

I’ve just released PHPShortener, a PHP class that makes it very easy to encode/decode URLs with services such as tr.im, is.gd, and others.

Encoding and decoding is a simple as this:

$s = new PHPShortener();
// encode a long url
$shorturl = $s->encode('http://devthought.com/projects/php/phpshortener/', 'is.gd');
// decode a short url (autodetects the service)
$longurl = $s->decode('http://tr.im/jBBp');

Head to the project page for downloads and documentation. Fork me on GitHub if you want to contribute!

14 Comments

Pies said

Wouldn’t it be easier to decode using CURL with CURLOPT_FOLLOWLOCATION set to false? This should give you access to “Location: …” headers which should in turn let you find out the target URL without using any APIs and for all possible services.

    Guillermo Rauch said

    The script can’t assume everyone has cURL. Plus decoding doesn’t use any APIs (can use though).

Simbioziz said

Очень интересно что это такое! Если кто может пояснить, поясните!!! Очень прошу! Я так понимаю это что-то вроде замены URL на необходимый, если не прав то поправте!))

asdf said

asdfasdf

good post, you could quite easily, however, add (to look exactly like every other blog out there) to the end of the title.

Anonymous said

It seemed hard to learn.

Anonymous said

Is it difficult to understand PHP URL?

Your thoughts?

About Guillermo Rauch:

CTO and co-founder of LearnBoost, developer, open source enthusiast, blogger.