Create Bit.ly Short URLs Using PHP
One of the more popular URL shortening services is Bit.ly. I've showed you how to create short URLs with TinyURL and Is.Gd, so why not show you how to create Bit.ly URLs remotely?
/* make a URL small */
function make_bitly_url($url,$login,$appkey,$format = 'xml',$version = '2.0.1')
//create the URL
$bitly = 'http://api.bit.ly/shorten?version='.$version.'&longUrl='.urlencode($url).'&login='.$login.'&apiKey='.$appkey.'&format='.$format;
//get the url
//could also use cURL here
$response = file_get_contents($bitly);
//parse depending on desired format
if(strtolower($format) == 'json')
$json = @json_decode($response,true);
$xml = simplexml_load_string($response);
/* usage */
$short = make_bitly_url('http://davidwalsh.name','davidwalshblog','R_96acc320c5c423e4f5192e006ff24980','json');
echo 'The short URL is: '.$short;
// returns: http://bit.ly/11Owun
Note that Bit.ly requires you to sign up for an account. Once you have an account, you may attain your login and URL information. I've also created functionality to recieve the shortened URL using JSON or XML.
I work with an awesome cast of developers at Mozilla, and one of them in Daniel Buchner. Daniel's shared with me an awesome strategy for detecting when nodes have been injected into a parent node without using the deprecated DOM Events API....
One event that's always been lacking within the document is a signal for when the user is looking at a given tab, or another tab. When does the user switch off our site to look at something else? When do they come back?...
Last week we created a very simple MooTools slideshow script. The script was very primitive: no events and no next/previous controls -- just cross-fading between images. This tutorial will take the previous slideshow script a step further by:
Adding "Next" and "Previous" controls.
Another reason that I love Twitter so much is that I'm able to check out what fellow developers think is interesting. Chris Coyier posted about a flashlight effect he found built with jQuery. While I agree with Chris that it's a little corny, it...
I'll be first person to admit I don't do as much git repository maintenance as I should. I rarely delete branches which have been merged, so a
git branch execution shows me a mile-long list of branches that likely aren't relevant. The best way to find branches I've recently...
Looking for the right resources to help you satisfy the needs of your clients? On the lookout for the best tools to help you increase your revenue? Searching for the right software to help you improve your business? Well, then you’ve come to the right place....
O'Reilly puts on the best web industry conferences in the world. These conferences include Fluent Conference, Velocity Conference, and the upcoming OSCON in Portland, Oregon from July 20-24. Open Source Convention (OSCON) is a conference that focuses specifically on open source developers and the tools and possibilities...
A while back I shared my favorite Google Chrome extension: Google Art Project. I've enjoyed seeing beautiful art when I open a new tab -- it's brought genuine happiness to my day, however small that happiness may be. About a week ago, however, the art presented had...