tcelestino

short url with bit.ly

Jan 23rd, 2012
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. function curl_get_result($url) {
  2.   $ch = curl_init($url);
  3.   $timeout = 50;
  4.   curl_setopt($ch,CURLOPT_URL,$url);
  5.   curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  6.   curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  7.   $data = curl_exec($ch);
  8.   curl_close($ch);
  9.   return $data;
  10. }
  11.  
  12. function encurtaURL($link) {
  13.    
  14.     $formato = "json";
  15.     $login = "tcelestino";
  16.     $apiKey = "R_29276446d8e3c7def8c2cce4b136df13";
  17.  
  18.     //acessa a api do bit.ly
  19.  
  20.     $bitly = 'https://api-ssl.bitly.com/v3/shorten?login='.$login.'&apiKey='.$apiKey.'&longUrl='.urldecode($link).'&format='.$formato;
  21.    
  22.    
  23.      return var_dump(curl_get_result($bitly));
  24.  
  25. }
  26.  
  27. echo encurtaURL("http://google.com.br");
Add Comment
Please, Sign In to add comment