PHP regular expression to determine the browser language instance. PHP function instances are used to determine the browser's default language based on regular expressions. In fact, php judges the browser language and uses the Super global variable _ SERVER [HTTP_ACCEPT_LANGUAGE]. However, PHP function instances can be used to determine the browser language, the default browser language is determined based on regular expressions. In fact, php judges the browser language using the Super global variable _ SERVER ["HTTP_ACCEPT_LANGUAGE, then, based on the Accept-Language: header information of the HTTP request, use regular expression matching to determine the Language type.
PHP judgment browser instance function:
01
02 $ lang = substr ($ _ SERVER ['http _ ACCEPT_LANGUAGE );
03 // only the first four digits can be used to determine the preferred language
04if (preg_match ("/zh-c/I", $ lang ))
05 echo "simplified Chinese ";
06 else if (preg_match ("/zh/I", $ lang ))
07 echo "traditional Chinese ";
08 else if (preg_match ("/en/I", $ lang ))
09 echo "English ";
10 else if (preg_match ("/fr/I", $ lang ))
11 echo "French ";
12 else if (preg_match ("/de/I", $ lang ))
13 echo "German ";
14 else if (preg_match ("/jp/I", $ lang ))
15 echo "Japanese ";
16 else if (preg_match ("/ko/I", $ lang ))
17 echo "Korean ";
18 else if (preg_match ("/es/I", $ lang ))
19 echo "Spanish ";
20 else if (preg_match ("/sv/I", $ lang ))
21 echo "Swedish ";
22 else
23 echo $ _ SERVER ["HTTP_ACCEPT_LANGUAGE"];
24?>
When using this function, you only need to call the function name. this function automatically returns the detection result.
Token can be obtained, however...