pratik
pratik

Reputation: 983

How to detect browsers language and check the language is spanish or english?

in my website i have two options one is english and one is spanish.

for english=en-US,en;q=0.5 and for spanish=es-es, es; q = 0,5.

I used $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];

now i want to check the condition and chage the logo of my websites.but every time its gives me bad result.how can i do that.anyhelp will be appricated.

Upvotes: 0

Views: 311

Answers (1)

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

you could do:

$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
switch ($lang){
    case "es":   //spanish
        include("logo_es.php");
        break;
    case "en":  //english and any other language
    default:
        //for english and default
        include("logo.php");
        break;
}

Upvotes: 2

Related Questions