-
-
Save 0xnbk/614512 to your computer and use it in GitHub Desktop.
PHP code to query goo.gl to shorten an url ( your php api for google url shortening )
This file contains 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 | |
// uses Google's http://goo.gl/ URL shortener | |
/* Enter your url below */ | |
$url = "aroundtheweb.info"; | |
/* Function to get the short url */ | |
function get_short_url($url) { | |
$ch = curl_init("http://goo.gl/api/url?url=" . urlencode($url)); | |
curl_setopt($ch, CURLOPT_POST ,1); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
if($result = curl_exec($ch)) | |
{ | |
$json = json_decode($result); | |
if($error = ($json->error_message)) | |
{ | |
echo "$error"; | |
exit; | |
} | |
$short_url = $json->short_url; | |
return "$short_url"; | |
} else | |
{ | |
echo curl_error($ch); | |
} | |
} | |
echo "Url: $url\n"; | |
echo "Shortened url by goo.gl: ".get_short_url($url); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi nikhil :)
please provide full code of shorter url..