Convert long url to short url using tinyurl api

Tinyurl provides us a short and simple service to convert long URL to small(tiny) URL. We can send email without link breakage.
Here is the tinyurl api to get shorten url. You can use any of the method.

Method 1:


Use file_get_contents to fetch tinyurl.

echo file_get_contents('http://tinyurl.com/api-create.php?url=http://www.websnippetz.com');

file_get_contents is not working? If your are able to access php.ini file set allow_url_fopen = On or you can use the below method.

Method 2:


Use cURL(runs faster than file_get_contents) to fetch tinyurl.

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

Comments

  1. [...] and a tip of the hat to WEBSNIPPETZ : Convert long url to short url using tinyurl api Previous Topic: Tempe Daytime Photo [...]

    ReplyDelete
  2. [...] and a tip of the hat to WEBSNIPPETZ : Convert long url to short url using tinyurl api Previous Topic: Tempe Daytime Photo [...]

    ReplyDelete

Post a Comment

Popular posts from this blog

Send email from xampp localhost

Modify item price in cart after placing order using sales_quote_add_item