Jun
30
2009
30
2009
Create short links using bit.ly from php
bit.ly is a simple url shortner which has an api , which can be called from within php to shorten links.
Code :
function get_short_url($url)
{
$bitly_login = "your_login_name";
$bitly_apikey = "your_api_key";
$api_call = file_get_contents("http://api.bit.ly/shorten?version=2.0.1&longUrl=".$url."&login=".$bitly_login."&apiKey=".$bitly_apikey);
$bitlyinfo=json_decode(utf8_encode($api_call),true);
if ($bitlyinfo['errorCode'] == 0)
{
return $bitlyinfo['results'][urldecode($url)]['shortUrl'];
}
else
{
return false;
}
}
The above function can be used to shorten a big url , as :
if ($shortlink = get_short_url("http://www.google.com/"))
{
echo $shortlink;
}
else
{
die("An error shortening the url");
}
The function needs an api key. To get your api key simply register at bit.ly then go to My Account and get your api key.
Popularity: 1% [?]
Tags: php
Related Posts
Leave a comment
Subscribe
Recent Posts
- Compile wxwebconnect on Ubuntu 11.04 64 bit
- Disqus Comments Importer Script in PHP
- Beginners’ guide to socket programming with winsock
- Handle multiple socket connections with fd_set and select on Linux
- Beginners guide to socket programming in C on Linux
- Gui whois client in python with wxpython
- Whois client code in C with Linux sockets
- str_replace for C
- Easy to use C/C++ IDE for Ubuntu Linux
- Get local ip in C on linux
Binarytides
Tags
apache
applications
box2d
bsnl
c
chrome
cron
css
database
dns
firefox
flash
freelance
game programming
gd
graphs
hacking
htaccess
html
html5
imagemagick
java
javascript
libpcap
linux
mod rewrite
moneybookers
mootools
mvc
mysql
networking
payment
paypal
php
phpmyadmin
python
ruby
security
Sockets
software
swing
ubuntu
winpcap
winsock
xdebug
An article by Binary Tides




