Fiz para um app aki,pode ser útil para outros,tou postando. =P class.bitLy.php: <?php
/*
* class para shorter url,usando bit.ly
* this class created by: Dr_h0us3 (-:
* MSN: h0us3_@hotmail.com
* http://www.orkut.com.br/Profile?uid=16257504973955089907
* exemplo de uso:
* require 'class.bitLy.php';
* $tmp = new bitLy;
$tmp->setURL('http://google.com');
echo $tmp->main();
*/
class bitLy
{
public function setURL($url){
$this-> url = $url;
return $url;
}
private function validarURL($url){
if(!preg_match("/[a-z]{3,5}:\/{2}/i",$url)) die("URL invalida");
return $url;
}
private function curl($page,$header,$post){
$ch = curl_init();
curl_setopt_array($ch,array(
CURLOPT_URL => $page,
CURLOPT_HEADER => $header,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => ($post)?'POST':'GET',
CURLOPT_POSTFIELDS => $post,
)
);
return ($r=@curl_exec($ch))?$r:curl_error($ch);
if(empty($r)) die("Error na conexão com $page");
}
public function main(){
$x = $this->curl("http://bit.ly/?s=&keyword=&url=".rawurlencode($this->validarURL($this->url)),false,false);
preg_match_all('/<textarea[^>]+.([^<]+)/i',$x,$url);
return $url[0][1];
}
}
?>
Exemplo de uso:
<?php
require 'class.bitLy.php';
$tmp = new bitLy;
$tmp->setURL("http://codepad.org/KYZ4xBKM");
echo $tmp->main();
?>