Criando uma TinyURL com PHP

March 1st, 2009 | Tags: , , , ,

TinyURL é um serviço fantástico. Para aqueles que não sabem o que é TinyURL, TinyURL lhe permite ter uma URL longa como “http://davidwalsh.name/jquery-link-nudging” e transformá-lo em “http://tinyurl.com/67c4se” .

Utilizando o PHP e TinyURL API, você pode criar esses minúsculos URLs na mosca!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//pega o valor da URL    
function get_tiny_url($url)    
{    
    $ch = curl_init();    
    $timeout = 5;    
    curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);    
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);    
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);    
    $data = curl_exec($ch);    
    curl_close($ch);    
    return $data;    
}  
 
//pra testar  
$new_url = get_tiny_url('http://davidwalsh.name/php-imdb-information-grabber');  
 
//retornou http://tinyurl.com/65gqpp  
echo $new_url

Espero que tenha sido útil. Vi no http://davidwalsh.name.

Abraços, ótimo domingo a todos!!


  1. April 30th, 2009 at 09:42
    Reply | Quote | #1

    Muito interessante..
    Valeu!

  2. November 18th, 2009 at 10:00
    Reply | Quote | #2

    Trabalhando neste função da pra fazer URL amigaveis