PHP applications of the garbage problem

Author:Anonymous    Updated:2008-10-16 18:43:51
1) the use of labels set up the page code

The label is a statement of the client browser used in any character set encoding that the page, xxx for GB2312, GBK, UTF-8 (and MySQL different, MySQL is UTF8), and so on. As a result, most of the pages can be used in this way to tell the browser to display the page when what coding, so that it will not cause an error code and produce garbage. But sometimes we would have found this or not, no matter what kind of xxx, the browser used is always a kind of code, this situation behind me to the talks.

Please note that the information belongs to the HTML, just a statement, the server has only shown that the information conveyed to the HTML browser.

2) header ( "content-type: text / html; charset = xxx");

The functions header () is the role of information inside the brackets made to the http headers. If the inside of the brackets for the content of the article said, and the role of the label that is basically the same, we were the first to see almost all the characters found. But the difference is that if this function, the browser will always use your xxx required by the code, never disobedient, so this function is very useful. Why is it so? Would have to talk about HTML and http header information of the differences:

http header is the http server to send the agreement to the browser HTML message sent before the string. The tags are HTML messages, the header () to send the content to reach the browser is popular point header () higher than the level of priority (do not know can not say). Php if an existing page header ( "content-type: text / html; charset = xxx"), and the browser only to identify the former rather than http header to identify the meta. Of course, this function can only be used in php page.

Also left a question on why the former definitely play a role, which sometimes does not work? This is the next to talk about the reasons for the Apache.

3) AddDefaultCharset

Apache root of the conf folder, there is a whole Apache configuration file httpd.conf.

Using a text editor to open httpd.conf, the first line 708 (different versions may be different) have AddDefaultCharset xxx, xxx for the name of the code. This is the meaning of lines of code: the entire set of servers http page document marked in advance for your character set the default character set xxx. This line, to the equivalent of each document are added his header ( "content-type: text / html; charset = xxx"). This clearly understand why on the next set is utf-8, the browser can always adopt gb2312.

If there are pages header ( "content-type: text / html; charset = xxx"), they changed the default character set you set the character set, so this function is always useful. If AddDefaultCharset xxx plus in front of a "#" out of this, but also in non-page header ( "content-type ..."), this time it will turn meta tags play a role.

The following is a list of more than Priority:

.. Header ( "content-type: text / html; charset = xxx")

.. AddDefaultCharset xxx

..

If you are a web programmer, to the proposals of each page you have to add a header ( "content-type: text / html; charset = xxx"), so that it can guarantee the right of any server can show that the portability Relatively strong.

4) php.ini configuration of default_charset:

php.ini in default_charset = "gb2312" a php defined the default language character sets. General recommended the trip out, so that browsers based on the first page of the charset to automatically select the language and not a mandatory requirement, thus able to offer servers with multi-lingual web services.
Previous:fscok Asynchronous call PHP
Next:PHP used in ASP.NET AJAX
User Reviews
Site Search
Recommended article
AD