PHP function instance, based on regular expressions to determine the browser's default language, in fact, PHP judgment browser language using Super global variable _server["http_accept_language" can be obtained, And then according to the HTTP request Accept-language: header information with regular match, finally determine the language type.
PHP determines the browser instance function:
01
02$lang=substr ($_server[' http_accept_language '],0,4);
03//only the first 4 digits, can judge the most preferred language
04if (Preg_match ("/zh-c/i", $lang))
echo "Simplified Chinese";
06else if (Preg_match ("/zh/i", $lang))
"Traditional Chinese";
08else if (Preg_match ("/en/i", $lang))
echo "中文版";
10else if (Preg_match ("/fr/i", $lang))
echo "French";
12else if (Preg_match ("/de/i", $lang))
echo "German";
14else if (Preg_match ("/jp/i", $lang))
echo "Japanese";
16else if (Preg_match ("/ko/i", $lang))
echo "Korean";
18else if (Preg_match ("/es/i", $lang))
echo "Spanish";
20else if (Preg_match ("/sv/i", $lang))
echo "Swedish";
22else
$_server[echo "Http_accept_language"];
24?>
This function automatically returns the test result when it is used only by invoking a function name.
http://www.bkjia.com/PHPjc/765432.html www.bkjia.com true http://www.bkjia.com/PHPjc/765432.html techarticle PHP function instance, based on the regular expression to determine the browser's default language, in fact, PHP judgment browser language using Super global variable _server[http_accept_language] can be obtained, ...