Skip to content

Instantly share code, notes, and snippets.

@sarfraznawaz2005
Last active October 12, 2015 18:32
Show Gist options
  • Save sarfraznawaz2005/7eece51fe0207c48fd21 to your computer and use it in GitHub Desktop.
Save sarfraznawaz2005/7eece51fe0207c48fd21 to your computer and use it in GitHub Desktop.
Short URLs using bit.ly
<php
function shortURL($url)
{
$url = urlencode($url);
$ch = curl_init('http://api.bitly.com/v3/shorten?login=sarfraznawaz2005&apiKey=R_182a565c28e4eafd0e23aa113464e73e&longUrl=' . $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$resultArray = json_decode($result, true);
$shortURL = $resultArray['data']['url'];
return $shortURL ? $shortURL : $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment