How to Dynamically Shorten URLs with TinyURL?

The URL shortening service TinyURL.com provides an API for programmatically processing URL shortening requests through your own script.

It’s actually pretty easy.

function short($url) {
    return file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
}

Alternatively, you can use cURL to download remote URLs contents if your server doesn’t support file_get_contents.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.