Instead of testing for either German or English being the FIRST language in the user's preferences, you should test which language comes before the other, no matter where in the list they appear.
The code for that could look something like this: $sorted_languages = ""; foreach ($langs as $lang = $val) $sorted_languages .= $lang .
Now your site is visited by a user speaks no English, only French, German and Italian and who has set his browser to prefer French over German, thus: fr,de;q=0.8,it;q=0.2.
lang=en That way the language is passed as a parameter value rather than the parameter being the value. with best regards, Lummo I don't know where Lummo got those BNFs for the Accept-Language header, but they do not conform to BCP 47. White space is not allowed within the tag and all tags are case- insensitive. No new dialects are allowed to be defined that are fewer than 5 chars long, so it could be except that there are extant cases such as en-OED (oxford english dictionary spellings) where as few as 3 letters are used. It seems that all the href contents have to be the same for each language.
See page 4 of RFC 4646: Something like (I do not write BNF for a living): 2*4ALPHA (["-" 4ALPHA] ("-" 2ALPHA (["-x] "-" 3*8ALPHA))) allowing tags like "sco-Latn-GB-x-lallans" or "en-oed": language-Script-COUNTRY-x-dialect the x prefix is for unofficial dialects (ebonics) and not needed for official ones (OED, Scouse) In short, the regex needs to be amended something like this: [a-z A-Z](-[A-Z][a-z])? Looks like I was behind the times :-) Cheers, Lummo Btw, RFC 4646 (page 5) says: The tags and their subtags, including private use and extensions, are to be treated as case insensitive: there exist conventions for the capitalization of some of the subtags, but these MUST NOT be taken to carry meaning. we could either do [A-Z][a-z] .../i for the script code, and allow three-char dialects, or [a-z] for four char script codes, and [a-z] for the dialect with a /i at the end. I am working on an easier and more flexible solution but this margin is too narrow to contain the details.
For some reason I misunderstood this content negotiation syntax for a while. I'm a native English speaker living in China and it drives me nuts when I go to some major websites and am automatically given the Chinese version.
But reading and re-reading the specs cleared things up: sorry for the confusion. I can read a little Chinese, but sometimes its even hard to find the link to go to the English-language version.