Coding problems for PHP Web pages

Source: Internet
Author: User

Analysis of the coding problem of Apache and PHP Web pages

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

<meta http-equiv= in HTTP Markup Language "Content-type" content= text/html; Charset=xxx "> Label
Header in PHP ("content-type:text/html; Charset=xxx "); function
Adddefaultcharset in the Apache configuration file httpd.conf
One, <meta http-equiv= "Content-type" content= "text/html; Charset=xxx "> Label
In order, first say this <META> label, this tag has a lot of features, specifically please click here.
I would like to say today just the form mentioned above. Explain <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "", meaning that the page is declared, so that the browser to the entire content of the page using the XXX code, XXX can be gb2312,gbk,utf-8 (and MySQL is different, MySQL is UTF8) and so on. Therefore, most of the pages can be used in this way to tell the browser to display the page when the code, so that will not cause coding errors generated garbled. But sometimes we will find that there is no, no matter what XXX is, the browser is always a kind of coding, which I will talk about later.
Note that,<meta> is an HTML message, just a statement that works to show that the server has uploaded HTML information to the browser.

Second, header ("content-type:text/html; Charset=xxx "); The
Function 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 article, the function and <META> tags are basically the same, and we can see the same characters as the first one. But the difference is that if you have this function, the browser will always use your request for the XXX code, will not be disobedient, so this function is very useful. Why is that? Then let's talk about the difference between HTTPS headers and HTML information:
Reference:
The HTTPS header is a string sent by the server before the HTTP protocol is used to send HTML information to the browser.
Because META tags are HTML information, the header () is sent to the browser first, and the popular point is that header () has precedence over meta (I don't know if it's possible). Join a PHP page with both header ("content-type:text/html; Charset=xxx "), there are <meta http-equiv=" Content-type content= "text/html; Charset=xxx "", the browser will only recognize the former HTTP headers and not to recognize Meta. Of course, this function can only be used within the PHP page. The
also leaves a question, why does the former work absolutely, and the latter sometimes? That's why we're going to talk about Apache next.

Third, Adddefaultcharset
In the Conf folder of the Apache root directory, there is the entire Apache configuration document HTTPD.CONF. Specifically how to configure Apache please click here ([Url=thread-2674-1-1.html]windows[/url],[url=thread-1381-1-1.html]linux[/url]).
Open httpd.conf with a text editor, 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 within the page file HTTPS header of the character set for your default XXX character set. With this line, it is equivalent to adding a line header to each file ("content-type:text/html; Charset=xxx "). This makes clear why obviously Meta set is utf-8, but browsers always use the gb2312 reason.
If the page has header ("content-type:text/html; Charset=xxx "), the default character set is changed to the character set of your setting, so this function is always useful. If you put a "#" in front of adddefaultcharset xxx, comment out the sentence, and the page does not contain header ("Content-type ..."), then the META tag will work.


Summarize:
A sort of.

Header ("content-type:text/html; Charset=xxx ")
Adddefaultcharset xxx
<meta http-equiv= "Content-type" content= "text/html; Charset=xxx ">
If you're a web programmer, add a header to every page you have ("content-type:text/html; Charset=xxx "), to ensure that it can be correctly displayed on any server, the portability of strong.
As for that sentence adddefaultcharset xxx, should not comment on the beholder. Anyway, I was commented out, but I write the page header (), easy to put on a different server can be displayed normally.

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.