reenadak

shorten url

Feb 20th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1.     /*
  2.     - Shorten URL (tinyurl)
  3.     - Sends a request to tinyurl's API via cURL to shorten the specified URL
  4.     - Returns the resulting short URL
  5.    
  6.     $link     - The http URL to shorten
  7.     $timeout  - How many seconds to wait before giving up
  8.     */
  9.    
  10.     public function tinyUrl($link, $timeout = 5) {
  11.         $ch = curl_init();
  12.        
  13.         curl_setopt($ch, CURLOPT_URL, "http://tinyurl.com/api-create.php?url=" . $link);
  14.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  15.         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  16.        
  17.         $data = curl_exec($ch);
  18.         curl_close($ch);
  19.        
  20.         return $data;
  21.     }
Add Comment
Please, Sign In to add comment