PHP Code _php Tutorial

Source: Internet
Author: User
First, page encoding
1. Use 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.
Please note that Is HTML information, just a declaration, it works to indicate that the server has uploaded HTML information to the browser.
2. Header ("content-type:text/html; Charset=xxx ");
The function of the header () is to send the information inside the parentheses to the HTTP header.
If the contents of the parentheses are what is said in the text, that function and The labels are basically the same, and the characters are similar to the first one you see. 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 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 if this can be said). Add a PHP page to both headers ("content-type:text/html; Charset=xxx "), and there , the browser will only recognize the HTTP header instead of Meta. Of course, this function can only be used within PHP pages.
There is also the question of why the former is absolutely working, and the latter sometimes not. This is the reason for the next Apache to talk about.
3. Adddefaultcharset
Apache root directory in the Conf folder, there is the entire Apache configuration document HTTPD.CONF.
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.
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 also to write the header (), easy to put on the server can be displayed properly.
Second, the database code
PHP program before querying the database, first execute mysql_query ("SET NAMES xxxx"), where xxxx is your Web page encoding (charset=xxxx), if the page Charset=utf8, then Xxxx=utf8, if the page charset=gb2312, xxxx=gb2312, almost all web programs, there is a connection to the database of common code, placed in a file, in this file, add mysql_query ("set names") on it.
Set NAMES shows what character set is used in the SQL statement sent by the client. Therefore, the set NAMES ' utf-8 ' statement tells the server that "the information coming from this client will be in character set Utf-8". It also specifies a character set for the result that the server sends back to the client. (For example, if you use a SELECT statement, it indicates what character set the column values use.) )

Author "dancer Blog" true techarticle First, page encoding 1. Use META http-equiv=content-type content=text/html; charset=xxx tag set page encoding the function of this tag is to declare what character set the client's browser uses ...

  • Related Article

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