Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //função do curl
- function curl_get_result($url) {
- $ch = curl_init($url);
- $timeout = 50;
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
- $data = curl_exec($ch);
- curl_close($ch);
- return $data;
- }
- function shortURL($link) {
- $format = "json"; //formato da URL
- $login = ""; // digite o login do bit.ly
- $apiKey = ""; //insira a key da api (http://bitly.com/a/your_api_key/)
- //pega as informações e passa para a API
- $bitly = 'https://api-ssl.bitly.com/v3/shorten?login='.$login.'&apiKey='.$apiKey.'&longUrl='.urldecode($link).'&format='.$format;
- $getURL = curl_get_result($bitly);
- $json = @json_decode($getURL, true);
- return $json['data']['url'];
- }
- echo shortURL("http://google.com");
- ?>
Add Comment
Please, Sign In to add comment