dtng25909 2016-08-08 10:23
浏览 62

获取Windows用户语言设置值

Is there any way to know the client machines language settings? specifically the List separator (Delimiter) selected. Because, in my project website (Developed using PHP, Javascript, Jquery) the client can export reports in csv format. At present we are creating this csv with "comma" as the delimiter. But for some of our clients , when they open this CSV the datas are showing in one column itself with comma separated.

I understood this is because the default List separator selected in their OS control panel configuration may be a different delimiter than comma. However, we don't want to tell to every client to change their OS configuration.. Is there any other solution for this? If i generate xls file instead of csv this same issue will come in future right???

  • 写回答

1条回答 默认 最新

  • dsgk40568 2016-08-08 10:29
    关注

    Try this function

    function getUserLanguage() {
      $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);
     }
    }
    //extract most important (first)
    foreach ($langs as $lang => $val) { break; }
    //if complex language simplify it
    if (stristr($lang,"-")) {$tmp = explode("-",$lang); $lang = $tmp[0]; }
    return $lang;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化