New Google website translator gadget

It was International Translation Day on 30th September and Google gifted users a new version of their website translator gadget.

From usability point of view this version is far more better then previous one and supports 51 languages. Earlier version of this gadget was a bit ugly in the manner it worked. It used to load the entire page in an iFrame which appeared like a full page reload every time user changed the language. It seems that the new gadget translates the page of text asynchronously. There is a progress indicator too which shows percentage of translation done. It is certainly faster then previous version.

There is one more feature to it. According to google if the language of a users browser visiting your page is different than the language of your page, they will be prompted to automatically translate the page in their language.

To use the gadget in your website just visit google at and follow these 3 steps:

  • Select the language of your website.
  • Select languages in which you want the translation.
  • Copy the generated code in your webpages and you are ready to go.

Although the translation is not 100% correct, it is a great help to read and understand text of foreign languages.

Collection of 10 top 10 lists about web development

I am a regular reader of web development articles and in this process bookmark a lot of them. Out of that collection I present to you a list of 10 articles which themselves are lists of 10(tips, functions etc). Not all of them are top 10 😉 but equally good. All these articles are related to php, javascript, html, mysql and web development in general.

1- 10 code snippets for PHP developers

Simple and handy functions for common tasks like validating email address and XSL transformation.


2- 10 Advanced PHP Tips Revisited

Detailed and excellent tips from famous PHP gurus Chris Shiflett and Sean Coates.


3- Top 10 PHP frameworks

PHP frameworks are quite popular among developers these days. This site is dedicated to php frameworks alone. In this article all frameworks have been compared for features. Very useful to help you in decision making if you are planning to use a framework for your next project.


4- Top 10 custom JavaScript functions of all time

This is my favorite one. These 10 functions are a must in every web developer’s toolbox. Functions like getElementsByClass, toggle and cookie functions are included.


5- 10 JavaScript Quick Tips and Best Practices

Another good article on javascript best practices.


6- Top 10 Firefox Addons For Web Developers

Who hasn’t heard of Firebug or GreaseMonkey. This article lists similar addons for firefox that are a great help in web development.


Continue reading Collection of 10 top 10 lists about web development

Quick PHP Tip: How to parse CDATA sections using SimpleXML

Applies to:  simplexml_load_string and simplexml_load_file

Problem : SimpleXML does not parse text inside CDATA tags in an XML.

Consider the XML below:

To parse it we use following syntax:

On printing it outputs:

Thats OK. Now the same xml but this time the text is enclosed in CDATA tags.

On printing this gives following output:

Yes its empty. This is because SimpleXML does not parse CDATA tags. All data enclosed within CDATA is ignored by SimpleXML parser.

Solution: Set the 3rd parameter to LIBXML_NOCDATA while parsing.

simplexml_load_string(simplexml_load_file too) actually takes 3 parameters.

  • The string to parse
  • Optional parameter – to return an object of class specified in this parameter. (By default it returns a SimpleXMLElement Object)
  • Also optional – libxml parameters can be specified as options. This option provides the solution to our CDATA problem

Provide the 3rd parameter LIBXML_NOCDATA and SimpleXML will consider CDATA nodes as text nodes and will parse them.

This will output as desired:

Please note that using the third parameter requires PHP >=5.1 compiled with libxml.

I will be publishing a new post shortly on how to use SimpleXML to parse xml and extract data.

javascript : 7 tips for better coding

1- Use short hand notation for declaring arrays and objects

Arrays and objects are declared as following:

There is a shorthand notation for declaring these which is much more easier to use. It can be used like this:

2- Use square bracket notation – [] – to access property of an object rather then using . (dot) notation

There is a good reason why you should do this. Suppose you have an object like following:

Properties of myObject can be accessed using either of the 2 ways.

Now assume you want to access these values dynamically (probably in a loop). Now see what happens.

If you take the first approach, you are in a mess. It will look for and will try to add the value of i to it and thus an error
Using the second method is safer and readable too.

3-    Break a long string into multiple lines

This surely makes code more readable. You can do it like below.

Think there is only one way of doing so? No, Here is another(lesser known) method:

Continue reading javascript : 7 tips for better coding

Super simple way to expand bitly urls using PHP

OK. Agree that provides an API for expanding URL’s. The main purpose of our simple exercise here is to use  curl functions in PHP to achieve the same. We will write a simple function that will accept a bitly url as parameter. Then we will use curl to get the expanded url.

Below is the full code for function which we will call expandURL.

How this works?

$retVal is the return value from function. First we initialize a curl session for bitly url using curl_init. Next 2 lines are most important.

Since our aim is not to display any output directly in browser, we will set CURLOPT_RETURNTRANSFER to 1 (true). It will  return the value after curl execution in a string and will not output anything to browser.

Continue reading Super simple way to expand bitly urls using PHP