Posted By

nerdsane on 02/11/09


Tagged

curl php shorturl hrefin


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

kurokikaze
jealousy


Create href.in short urls


 / Published in: PHP
 

URL: http://href.in/api_example.php

To use href.in API to generate a short URL. using php curl

  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://href.in/api.php?create='.$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://twitter.com/inerds');
  16.  
  17. //returns http://href.in/gh7uab
  18. echo $new_url

Report this snippet  

You need to login to post a comment.