· 5 years ago · May 10, 2020, 11:40 PM
1public static function shortenUrl($url)
2
3 {
4 $login = 'trustwothy';
5 $api_key = 'API KEY HERE';
6
7 $ch = curl_init('http://api.bitly.com/v3/shorten?login='.$login.'&apikey='.$api_key.'&longUrl='.$url);
8 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
9 $result = curl_exec($ch);
10 $res = json_decode($result, true);
11 return $res['data']['url'];
12 }