我正在使用这个脚本:
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
switch ($lang){
case "nl":
//echo "PAGE FR";
include("talen/nl.php");//include check session FR
break;
case "es":
//echo "PAGE IT";
include("talen/es.php");
break;
case "en":
//echo "PAGE EN";
include("talen/en.php");
break;
default:
//echo "PAGE EN - Setting Default";
include("talen/en.php");//include EN in all other cases of different lang detection
break;
}
但是当我将浏览器语言设置为“af”时,它没有获得默认的英语语言......
我怎样才能做到这一点?
编辑:
因为我没有案例“af”它没有显示任何东西......
当没有像“af”这样的情况时,我希望默认为“en”,但这不起作用
编辑2:
我现在正在使用这个:
<?
$accept_lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$accept_lang = str_replace(' ', '', $accept_lang);
$arr = explode(',', $accept_lang);
$lang = "en";
$q = 0;
if (count($arr) > 0) {
foreach ($arr as $a) {
$l = explode(';', $a);
if (count($l) == 1) {
$l[1] = 'q=1';
}
$l[1] = str_replace('q=', '', $l[1]);
if ($l[1] > $q) {
$q = $l[1];
$lang = $l[0];
}
}
}
$lang = preg_replace('/-(.*)/', '', $lang);
switch ($lang){
case "nl":
//echo "PAGE FR";
include("talen/nl.php");//include check session FR
break;
case "es":
//echo "PAGE IT";
include("talen/es.php");
break;
case "en":
//echo "PAGE EN";
include("talen/en.php");
break;
default:
//echo "PAGE EN - Setting Default";
include("talen/en.php");//include EN in all other cases of different lang detection
}
?>
但是我的 $lang 仍然设置为“af”而不是默认的“en”
编辑 3:
谢谢你的帮助:
当我尝试使用这个:
print $_SERVER['HTTP_ACCEPT_LANGUAGE'];
switch ($lang){
case "nl":
//echo "PAGE FR";
print("nl");//include check session FR
break;
case "es":
//echo "PAGE IT";
print("es");
break;
case "en":
//echo "PAGE EN";
print("en");
break;
default:
//echo "PAGE EN - Setting Default";
print("en");//include EN in all other cases of different lang detection
break;
}
它打印出这个:
af,nl;q=0.8,en;q=0.5,en-us;q=0.3en
但我仍然得到“af”..如何
只是为了让你知道......我将我的浏览器语言设置为“af”来测试它......只是你知道......但它应该用你的 sript 加载默认值......