How to Dynamically Shorten URLs with TinyURL?

How to Dynamically Shorten URLs with TinyURL?

Dzhuneyt Ahmed - Author of this post
Dzhuneyt Ahmed

Posted · 1 min read

Outdated: While TinyURL’s API may still work, URL shortening services have evolved significantly. Consider using the APIs from Bitly or Short.io for more reliable, feature-rich alternatives.

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.

Dzhuneyt Ahmed

Dzhuneyt

Helping teams build reliable cloud infrastructure — without the bloated bill.

Social

My Other Blogs

© 2026 Dzhuneyt Ahmed. All rights reserved.