Home  >  Article  >  Backend Development  >  PHP检测客户端用户语言函数

PHP检测客户端用户语言函数

WBOY
WBOYOriginal
2016-06-20 13:03:321247browse

function get_client_language($availableLanguages, $default='en'){<br />    if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {<br />        $langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);<br />        foreach ($langs as $value){<br />            $choice=substr($value,0,2);<br />            if(in_array($choice, $availableLanguages)){<br />                return $choice;<br />            }<br />        }<br />    } <br />    return $default;<br />}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn