From PHP script to browser, the analysis of encoding method

Source: Internet
Author: User

Today a simple look at PHP, server, browser How to set the encoding

1.php

In PHP configuration file php.ini, you can set the character encoding

; PHP 's default character set is set to empty; Http://php.net/default-charsetdefault_charset = "gb2312"

In PHP 5.6 and Beyond, "UTF-8" is the default (before 5.6 is a null value), for the following functions: Htmlentities (), Html_entity_decode () and Htmlspecialchars (), If their encoding parameters are omitted, then the value of Default_charset is used for the default encoding of these functions. For iconv functions, if their arguments input_encoding 3.output_encoding/internal_ Encoding, if not set, will also take the value of default_charset, for mbstring function, if Mbstring.http_input mbstring.http_output Mbstring.internal_ If encoding is not set, it will also take the Default_charset value,

In addition, it is not recommended to set Default_charset to a null value. (Setting default_charset to a empty value is not recommended).

The encoding type of the script must be consistent with default_charset, otherwise it will be garbled.

2. The server, such as Apache, will refer to the PHP.ini setting when returning the response header Content-type.

Like what:

// php.ini in default_charset = "AAABBCCC"
View response header: content-type:text/html; Charset=aaabbccc

If the header function is used in a PHP script, the server's response header will follow the header function's settings.

3. About meta settings in the corresponding entity Content-type

< Head >    <  charset= "UTF-8">    <title> Document</title></head>

Its priority is lower than the content-type specified in the response header, that is, the encoding type is specified in the response header, and the browser follows the settings of the response header (typically, the final decision is in the browser's hands)

4. Browser encoding settings

Compared to the Chrome,ff,360 browser, IE8, found that Chrome browser seems to ignore the user's manual settings, the specific mechanism does not understand, and other browsers, as long as the user has changed the encoding, will be encoded according to user-specified decoding

From PHP script to browser, the analysis of encoding method

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.