1//gets the data from a URL
2function 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 // instead of above code below can also be used.
13 // return file_get_contents('http://tinyurl.com/api-create.php?url='.$url);
14}
15
16//test it out!
17$new_url = get_tiny_url('https://davidwalsh.name/php-imdb-information-grabber');
18
19//returns http://tinyurl.com/65gqpp
20echo $new_url