Creating a TinyURL with the TinyURL API

The popular URL shortening service TinyURL provides a quick API that creates TinyURL’s on the fly. Here’s how you can access that API.

Make a call to our function above, and it outputs a new tinyURL.


19 thoughts on “Creating a TinyURL with the TinyURL API”

  1. Thank you for the example.

    What if:

    I need to make shorter multiple links. All that i need is a shorter url for each.

    Do you have any clue ?

    thank you.

  2. First off, thanks for this script; you saved me a bunch of time!

    Second, what I would like to do is use this in conjunction with a script I have that pulls the current URL of the page.

    So, in place of “http://www….” in your example, I need to supply your function with the resulting URL of the other function.

    I’ve tested both functions separately, and the both produce the desired output. I just can’t get them to work together.

    Any idea how I might accomplish such a feat?

    Thanks again

  3. We are playing around with using tinyURL to replace some of our dynamic encrypted keys. Can you advise on whether TinyURL can achieve the following

    1. At present we sell a software online that generates an email. This email contains a link that consists of up to 100 characters (encrypted – order – email etc included in the string) that when clicked will direct to an installation page and carry through the encrypted data needed.

    2. The problem we have is that a small number of people are not able to view the button (click here) that starts the automatic installation. The other problem is that a small number of people risk because of the string size not properly copy and paste the full licence key (installation URL)

    3. What I am thinking is that “In Theory” we can convert the URL installation (which contains hash characters MD5 and dynamic data) into a Tiny URL. The alternate text for the button would then appear as the TinyURL and therefore those people not able to see the button will not view a lengthy (and sometimes scary string) instead seeing a friendly – short – TinyURL.

    4. The end result is that then customers can copy and paste the Tiny URL (easier than previous URL) and then in a new browser easily start the installation process.

    So the keywords here are “In Theory” and it would be appreciated if someone could give me feedback on whether integrating the TinyURL API would in fact create function TinyURL for our Installation URL’s

    Thanks in advance…..

  4. Hey Richard –

    Thanks for saving me the time of scouring the web for this info!

    I am having a small-ish problem with permissions. My client has a hosting account with (VPS). When I run your script, I am getting the following errors, which I assume have to do with server settings:

    1. failed to open stream: no suitable wrapper could be found

    2. file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration

    Any thoughts?



  5. Hey Richard-

    Update on my above post. I found another method using CURL feature in PHP instead of get_file_contents. Here it is for your readers’ entertainment!

    Of course, I am using this to add a tinyurl to a Twitter post notifying followers of a new article on my client’s website. So coupling this with Twitter’s totally simple API, I am able to do this!

    Thanks for the article, it ultimately pointed me in the correct destination for my specific purposes!


  6. {syntaxhighlighter brush: php}

    // you must be stripping tags!

    //gets the data from a URL

    function get_tiny_url($url)


    $ch = curl_init();

    $timeout = 5;




    $data = curl_exec($ch);


    return $data;


    //test it out!

    $new_url = get_tiny_url(‘’);


    echo $new_url


  7. How many hits can make in a day or in 1 hour using tiny url shortenetng api.

    i need unlimited url shortener it is possible in tiny url shortening api.


    is there any other url api available for unlimited ..

    please help us

    Thaks in advance

Leave a Reply

Your email address will not be published. Required fields are marked *