Last active
October 12, 2015 18:32
-
-
Save sarfraznawaz2005/7eece51fe0207c48fd21 to your computer and use it in GitHub Desktop.
Short URLs using bit.ly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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