Sometimes you need to convert a url to a new one on the fly.  Tinyurl offers a very easy to use API to do that.  You can do it complicated with curl or you can just use file_get_contents and make it a one line function.

function ShortURL($ToConvert) {
$short_url= file_get_contents(“http://tinyurl.com/api-create.php?url=” . $ToConvert);
return $short_url;

}

Just call it with:

$newurl = ShortURL(‘http://www.linktoshorten.com/itsreallylong’);

 

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>