Posted By

Tamedo on 02/05/09


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

kurokikaze


auto create tinyurl


 / Published in: PHP
 

  1. //gets the data from a URL
  2. function get_tiny_url($url)
  3. {
  4. $ch = curl_init();
  5. $timeout = 5;
  6. curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);
  7. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  8. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  9. $data = curl_exec($ch);
  10. curl_close($ch);
  11. return $data;
  12. }
  13.  
  14. //test it out!
  15. $new_url = get_tiny_url('http://davidwalsh.name/php-imdb-information-grabber');
  16.  
  17. //returns http://tinyurl.com/65gqpp
  18. echo $new_url

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: ginoplusio on December 29, 2009

If you have to decode those short urls, you can use the CURL lib in this way: http://snipplr.com/view/25668/php-tiny-url-encode-and-decode-functions/

You need to login to post a comment.