Create href.in short urls


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.