Virajsinh

Tiny URL API

Dec 16th, 2019
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.49 KB | None | 0 0
  1. //gets the data from a URL  
  2. function get_tiny_url($url)  {  
  3.     $ch = curl_init();  
  4.     $timeout = 5;  
  5.     curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);  
  6.     curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
  7.     curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);  
  8.     $data = curl_exec($ch);  
  9.     curl_close($ch);  
  10.     return $data;  
  11. }
  12.  
  13. //test it out!
  14. $new_url = get_tiny_url('https://davidwalsh.name/create-tiny-url-php');
  15.  
  16. //returns http://tinyurl.com/65gqpp
  17. echo $new_url
Add Comment
Please, Sign In to add comment