Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Detect browser language

If your website is multilingual, it can be useful to detect the browser language to use this language as the default. The code below will return the language used by the client’s browser.

function get_client_language($availableLanguages, $default='en'){
foreach ($langs as $value){
if(in_array($choice, $availableLanguages)){
return $choice;
return $default;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment