Using the PHP HTTP_ACCEPT_LANGUAGE server variable

后端 未结 7 1387
梦毁少年i
梦毁少年i 2020-11-29 00:07

I created a PHP script that checks the HTTP_ACCEPT_LANGUAGE and loads the website using the appropriate language from the 1st two characters:

          $http         


        
7条回答
  •  甜味超标
    2020-11-29 00:45

    if you want to store languages in array, i do this:

    preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i',  'pt-br,pt;q=0.8,en-us;q=0.5,en,en-uk;q=0.3', $lang_parse);
    $langs = $lang_parse[1];
    $rank = $lang_parse[4];
    for($i=0; $i

    this output an array to languages e other with values

    preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', 'pt-br,pt;q=0.8,en-us;q=0.5,en,en-uk;q=0.3', $lang_parse);
    $langs = $lang_parse[1];
    $rank = $lang_parse[4];
    $lang = array();
    for($i=0; $i

    this output an array like this:

    Array
    (
        [pt-br] => 0.8
        [pt] => 0.8
        [en-us] => 0.5
        [en] => 0.3
        [en-uk] => 0.3
    )
    

提交回复
热议问题