PHP page encoding declaration with header or meta implementation of PHP page encoding Difference

Source: Internet
Author: User

PHP header to define a PHP page for UTF encoding or GBK encoding

PHP page is UTF encoded
Header ("content-type:text/html; Charset=utf-8 ");

PHP page is GBK encoded
Header ("content-type:text/html; charset=gb2312 ");

PHP page is BIG5 encoded
Header ("content-type:text/html; Charset=big5 ");

Usually the above code is placed on the homepage of the PHP page

the difference between PHP page encoding using header or meta
First, page encoding

1. Use <meta http-equiv= "Content-type" content= "text/html; Charset=xxx "> Label Settings page encoding

The purpose of this tag is to declare the client's browser with what character set encoding to display the page, XXX can be gb2312,gbk,utf-8 (unlike MySQL, MySQL is UTF8) and so on. As a result, most pages can use this method to tell the browser what code to use when displaying this page, so that it does not cause coding errors and garbled characters. But sometimes we will find that with this sentence or not, regardless of xxx is the kind of, the browser is always a kind of coding, this situation I will talk about later.&NBSP;

Note that,<meta> is HTML information and is simply a declaration that the server has uploaded HTML information to the browser. &NBSP;

2. Header ("content-type:text/html; Charset=xxx "); &NBSP;

The function of the header () is to send the information inside the parentheses to the HTTP header. &NBSP;

If the contents of the parentheses are the same as in the text, the function and the <META> tag are basically the same, and the characters are similar to the one seen in the first. But the difference is that if you have this function, the browser will always take the XXX code you require, absolutely will not be disobedient, so this function is very useful. Why is that? Let's talk about the difference between HTTPS headers and HTML information: &NBSP;

The HTTPS header is a string that the server sends HTML messages to the browser before the HTTP protocol. &NBSP;

because the META tag is HTML information, the header () sends the content first to the browser, the popular point is the header () Priority is higher than meta (I don't know if I can say that). Add a PHP page to both headers ("content-type:text/html; Charset=xxx "), but also <meta http-equiv=" Content-type "content=" text/html; Charset=xxx, the browser will only recognize the HTTP header of the former and not recognize Meta. Of course, this function can only be used within PHP pages. &NBSP;

Transferred from: http://www.jb51.net/article/22501.htm

PHP page encoding declaration with header or meta implementation of PHP page encoding Difference

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.