PHP page Coding Problem _php Tutorial

Source: Internet
Author: User
Analysis of encoding problems of Apache and PHP Web pages

Talk about the encoding of Apache and PHP Web pages. There is also an article about the MySQL character set: http://potatows.eeie.cn/?p=39
When it comes to Apache coding, we're going to have 3 things.

tags in the HTTP markup Language
Header in PHP ("content-type:text/html; Charset=xxx "); function
Adddefaultcharset in Apache configuration file httpd.conf
First, the label
In order to first say this tag, this tag has a lot of features, please click here.
I would like to say today is just the form mentioned above. Explain , meaning that the page is declared, so that the browser to the entire page of the content of XXX code, 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.
Note that the HTML information is only a declaration, which works to indicate that the server has uploaded HTML information to the browser.

Second, header ("content-type:text/html; Charset=xxx "); The function of the
header () is to send the information inside the parentheses to the HTTP header. Please click here for specific usage of this function.
If the contents of the parentheses are the same as in the text, the function and the 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 the HTTPS header and the HTML message: The
Reference:
HTTPS header is a string that the server sends HTML messages to the browser before the HTTP protocol.
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 do not know can be said). Add a PHP page to both headers ("content-type:text/html; Charset=xxx "), and also leaves a question, why does the former absolutely work, and the latter sometimes not? This is the reason for the next Apache to talk about.

Third, Adddefaultcharset
Apache root directory in the Conf folder, there is the entire Apache configuration document HTTPD.CONF. For details on how to configure Apache click here ([Url=thread-2674-1-1.html]windows[/url],[url=thread-1381-1-1.html]linux[/url]).
With a text editor open httpd.conf, line No. 708 (different versions may be different) has adddefaultcharset xxx,xxx as the encoded name. This line of code means: Set the entire Server Web page file in the HTTPS header of the character set for your default XXX character set. With this line, it is equivalent to adding a row header to each file ("content-type:text/html; Charset=xxx "). This will understand why the obvious meta set is utf-8, can browser always use gb2312 reason.
If there is a header in the page ("content-type:text/html; Charset=xxx "), the default character set is changed to the character set you are setting, so this function is always useful. If you put Adddefaultcharset xxx in front of a "#", comment out this sentence, and the page does not contain the header ("Content-type ..."), then this time the META tag has worked.


Summarize:
Sort of.

Header ("content-type:text/html; Charset=xxx ")
Adddefaultcharset xxx

If you are a Web programmer, add a header to each of your pages ("content-type:text/html; Charset=xxx ") to ensure that it can be displayed correctly on any server and is highly portable.
As for that sentence adddefaultcharset xxx, should not comment on the beholder. Anyway, I have commented out, but I write the page to write the header (), easy to put on different servers can be displayed properly.


http://www.bkjia.com/PHPjc/445140.html www.bkjia.com true http://www.bkjia.com/PHPjc/445140.html techarticle An analysis of the encoding problem of Apache and PHP pages on the encoding of Apache and PHP Web pages. There is also an article about the MySQL character set: http://potatows.eeie.cn/?p=39 talking about Apache coding we are going to involve ...

  • 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.