Posted By

frankyfish on 04/15/10


Tagged

php bitly


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

sumit270
dantreacy


php bitly


 / Published in: PHP
 

  1. function curl_get($url) {
  2. $curl = curl_init($url);
  3. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  4. curl_setopt($curl, CURLOPT_TIMEOUT, 30);
  5. $return = curl_exec($curl);
  6. curl_close($curl);
  7. return $return;
  8. }
  9.  
  10. /* returns the shortened url */
  11. function get_bitly_short_url($url,$format='txt',$login="",$appkey="") {
  12. $auth = ($login != "" && $appkey != "") ? "&login='.$login.'&apiKey=".$appkey : "" ;
  13. $connectURL = 'http://api.bit.ly/v3/shorten?uri='.urlencode($url).'&format='.$format.$auth;
  14. return curl_get($connectURL);
  15. }
  16.  
  17. /* returns expanded url */
  18. function get_bitly_long_url($url,$format='txt',$login="",$appkey="") {
  19. $auth = ($login != "" && $appkey != "") ? "&login='.$login.'&apiKey=".$appkey : "" ;
  20. $connectURL = 'http://api.bit.ly/v3/expand?shortUrl='.urlencode($url).'&format='.$format.$auth;
  21. return curl_get($connectURL);
  22. }

Report this snippet  

You need to login to post a comment.