PHP function instance, based on the regular expression to judge the browser's default language, in fact, PHP Judge browser language using Super global variable _server["http_accept_language"] can be obtained, Then according to the HTTP request Accept-language: header information with a regular match, the final judgment of the language type.
PHP to determine the browser instance function:
01<?php
02$lang=substr ($_server[' http_accept_language '],0,4);
03//only the first 4 digits to determine the most preferred language
04if (Preg_match ("/zh-c/i", $lang))
echo "Simplified Chinese";
06else if (Preg_match ("/zh/i", $lang))
echo "Chinese";
08else if (Preg_match ("/en/i", $lang))
echo "中文版";
10else if (Preg_match ("/fr/i", $lang))
One 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
echo $_server["Http_accept_language"];
24?>
This function automatically returns the result of the call when it is used only by calling a function name.