Need to know your visitor’s language? Detecting a browser’s language setting can quickly be accomplished with one line of PHP.

The above example would display either “es”, for example for Spanish, or the two-letter abbreviation “en” for English if the browser in question was either Spanish or English respectively. If the browser language was German it would be “de”. This is due to the fact that we are using a PHP substr() substring operator to retrieve just the first two characters from the PHP response of checking the browser language settings.

 

If you used the above code without the substring the following output might look something like this: