Yesterday. google launched an API for its URL shortening service http://goo.gl. Using this API developers will be able to expand/shorten URLs and get a user’s analytics and history programmaticaly.
Below is a small snippet of PHP code that expands a short URL. The response comes in JSON format, so we will use the json_decode function to convert it to object.
$shortUrl = 'http://goo.gl/WlFX';
$response = file_get_contents('https://www.googleapis.com/urlshortener/v1/url?shortUrl='.$shortUrl);
$json = json_decode($response);
if($json->status === "OK")
echo 'Bad luck.';
Here is the full successfull response in JSON format.
Finally, note that Google recommends the use of an API key. You can visit this link to read more about key and get a key from this link.
After using the key, your URL will look like the following:
$shortUrl = 'http://goo.gl/WlFX';
$apiKey = 'your_key_here';
$response = file_get_contents('https://www.googleapis.com/urlshortener/v1/url?shortUrl='.$shortUrl.'&key='.$apiKey);
This post contains some of the useful and interesting tech links I found during this week. To keep up to date with the latest information, subscribe to the feed or follow me on twitter @v08i
10 Google Chrome Extensions for a Faster Browser – http://goo.gl/slpTR
75+ Tools for Visualizing your Data, CSS, Flash, jQuery, PHP – http://goo.gl/K8771
Continue reading Favorite tech links of the week : 03 Jan – 09 Jan, 2011
Every web application requires configuration files which contain values that are used throughout the application. In this post we will look at some of the methods developers use to define configuration settings and also what should be avoided.
The ugly way
I have seen many many developers do this and am myself guilty of doing it during my initial coding days. Consider the following code.
Developers define 2 sets of same variables for each environment. First set is for development environment while second is for production. To switch the configuration developer must comment all other sets and uncomment the desired one. This is untidy and error prone. Never ever use this in your applications.
Continue reading PHP: Defining configuration values
Image Courtesy: Desizn Tech
2011 has begun and everyone on the web is either busy in making predictions for the web or taking resolutions for another year. This post reflects on plans that I have for this year. Personally, I don’t believe in resolutions that much. Adding to this fact that I am extremely lazy. So, absolutely no f****g guarentee for any of these to be complete. But it is always good to know where you are heading to. Here is what I plan to learn/achieve this year.
Write another book
Last year I got a chance to write a book on 2 of my favorite technologies : PHP and jQuery. The result was PHP jQuery Cookbook. Writing a book is an interesting and a great learning experience. You must know every word that you are writing because you cannot rollback once the words are out in print. Nevertheless, I would like to write one more book this year. Probably on Google APIs or various other APIs like facebook, twitter etc.
Read more blogs
I am an avid reader of web development blogs. Google reader and bookmarks toolbar are a great help. This year I will add more and more feeds so that I do not skip anything.
Continue reading A web developers rants for new year
Here is the situation. You have a really long table with hundreds of rows and you want to filter the rows(instantly!) that contain a specific keyword in any of the table cells.
This article will show how this can be achieved with the help of jQuery.
Continue reading Searching text in a HTML table using jQuery