detect user language in PHP - stable solution
<p>I'm currently working on a auto-user-language-detection for providing the content in the user's language.</p>

<p>of course its possible to change the language manually, but if a user visits the page for the first time I want to provide the content in his language.</p>

<p>So I was googling and found the $_SERVER['HTTP_ACCEPT_LANGUAGE']-Var to get a result like that:</p>

<blockquote>
  <p>de-de,de;q=0.8,en-us;q=0.5,en;q=0.3</p>
</blockquote>

<p>whats the best way to filter this result to get a clear result like "EN" / "DE" / "IT"?</p>

<pre><code>$rL = $_SERVER["HTTP_ACCEPT_LANGUAGE"]; //  de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
$langCode = strtoupper($rl[0].$rl[1]);
</code></pre>

<p>the second issue on this Server-Var is that its only give me a result if the browser provide some information. Is setting a default page language the only possibility to handle that?</p>

<p>The second possibility I'm interested in is to get the language by IP. So if I get the Language I probably know the language of the user. But whats in multi-language-countries like Switzerland, Belgium? Whats with tld's like .com / .net / .org and so on.</p>

<p>So which method would you apply to detect the users language?</p>

<p>thanks for helping.</p>
