Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: fc00c3929c
Fetching contributors…

Cannot retrieve contributors at this time

47 lines (39 sloc) 1.061 kB
<?php
/* script from
* http://www.thefutureoftheweb.com/blog/use-accept-language-header
*/
$langs = array();
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
// break up string into pieces (languages and q factors)
preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
if (count($lang_parse[1])) {
// create a list like "en" => 0.8
$langs = array_combine($lang_parse[1], $lang_parse[4]);
// set default to 1 for any without q factor
foreach ($langs as $lang => $val) {
if ($val === '') $langs[$lang] = 1;
}
// sort list based on value
arsort($langs, SORT_NUMERIC);
}
}
// look through sorted list and use first one that matches our languages
foreach ($langs as $lang => $val) {
switch("$lang")
{
case 'zh-tw':
header("Location: zh-tw/");
return;
case 'zh-cn':
header("Location: zh-cn/");
return;
case 'zh':
header("Location: zh-tw/");
return;
case 'en':
header("Location: en/");
return;
}
}
header("Location: en/");
return;
Jump to Line
Something went wrong with that request. Please try again.