Snippet : TinyURL API in PHP

This snippet helps you to shorten your URLs with TinyURL API(Function with usage)

  1. <?php
  2. function TinyURL($url){
  3.     return file_get_contents('http://tinyurl.com/api-create.php?url='.$url);
  4. }
  5. echo TinyURL('http://www.ultimateprogrammingtutorials.info');
  6. ?>
You need to replace http://www.ultimateprogrammingtutorials.info with the URL you want to shorten

1 comments:

Thanks.. much cleaner than:

$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;

Reply

Post a Comment

Note: Only a member of this blog may post a comment.