Home  >  Article  >  Backend Development  >  PHP implements jumping to different language page codes according to the browser_PHP tutorial

PHP implements jumping to different language page codes according to the browser_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:00:02998browse

Copy code The code is as follows:

$lan = $_SERVER['HTTP_ACCEPT_LANGUAGE']; //Get Browser language version
if (preg_match("/[zh]{2}-[hk]{2}/", $lan) || preg_match("/[zh]{2}-[tw]{2 }/", $lan)) {//Taiwan and Hong Kong go to the traditional Chinese page
$url = 'hk/index.php';
header("location: " . $url);
} elseif (preg_match("/(?i)^[en]/", $lan)) { //English countries go to the English page
$url = 'en/index.php';
header("location : " . $url);
} elseif (preg_match("/[zh]{2}-[cn]{2}/", $lan)) { //Go to the simplified Chinese page in mainland China
$ url = 'cn/index.php';
header("location: " . $url);
} else { //Others go to English or other pages
$url = 'en/index. php';
header("location: " . $url);
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328090.htmlTechArticleCopy the code as follows: ?php $lan = $_SERVER['HTTP_ACCEPT_LANGUAGE']; //Get the browser language Version if (preg_match("/[zh]{2}-[hk]{2}/", $lan) || preg_match("/[zh]{2}-[tw]{2}/"...
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