PHP Regular Expression Judgment Browser language instance _php tutorial

Source: Internet
Author: User
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, ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.