用PHP检测用户语言
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用PHP检测用户语言相关的知识,希望对你有一定的参考价值。
Function to detect user language in php.
function getPreferredLanguage() { // break up string into pieces (languages and q factors) $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse); // create a list like "en" => 0.8 // set default to 1 for any without q factor foreach ($langs as $lang => $val) { if ($val === '') $langs[$lang] = 1; } // sort list based on value } } //extract most important (first) foreach ($langs as $lang => $val) { break; } //if complex language simplify it return $lang; }
以上是关于用PHP检测用户语言的主要内容,如果未能解决你的问题,请参考以下文章