Unified page Encoding
MySQL database encoding, HTML page encoding, PHP or HTML files themselves are encoded to be identical.
1. MySQL Database code:
When you create a database, specify the encoding (such as GBK_CHINESE_CI), create a data table, create a field, insert data without specifying the encoding, and automatically inherit the database encoding.
When the database is connected, there is also code that can execute mysql_query (' SET NAMES GBK ') after the database is connected, and/or replace GBK with your code, such as UTF8.
2, the HTML page encoding, refers to the setting of this line:
<meta http-equiv= "Content-type" content= "text/html; CHARSET=GBK "/>
3, the Code of PHP or HTML file itself:
With EditPlus open PHP file or HTML file, save, select the encoding, if the database and page encoding is GBK, then the code here choose ANSI; If the database and page encoding is Utf-8, then Utf-8 is also selected here.
4. The data passed in JavaScript or Flash is UTF-8 encoded:
Also note that the data passed in JavaScript or flash is UTF-8 encoded, and if the database and page encoding is GBK, transcode and then write to the database.
Iconv (' Utf-8 ', ' GBK ', $content);
5, in the PHP program, you can add a line to specify the code of the PHP source program:
Header (' content-type:text/html; CHARSET=GBK ');
PHP page encoding
1. Set the encoding in the file header
<?php
@header (' Content-type:text/html;charset=utf-8 ');
?>
The difference between 2.header and meta
With @header (' content-type:text/html; CHARSET=GBK '), and <meta http-equiv= "Content-type" content= "text/html; CHARSET=GBK "/> The difference
They are all telling the browser what code to display the page, to say what is different, the header is to send the original HTTP header, do not leave anything in the page, and Meta is written in the Web page.
First, if there is no meta in the Web page, then sending the HTTP header will work.
Second, sending the original HTTP header with the header () function can contain more content, and setting the encoding is just one of them.
Third, sometimes do not display what the page content, but to inform the browser with what code for follow-up action.
PHP Page Coding Issues