Php page encoding unified page encoding
MySQL database encoding, html page encoding, PHP or html file encoding must all be consistent.
1. MySQL database encoding: specify the encoding (such as gbk_chinese_ci) when creating a database. do not specify the encoding when creating a data table, creating a field, or inserting data. This will automatically inherit the database encoding.
The database is also encoded when it is connected. after the database is connected, run
Mysql_query ('set NAMES gbk'); // replace gbk with your encoding, such as utf8.
2. html page encoding refers to the setting of this line:
3. PHP or html file encoding: use editplus to open the PHP file or html file. if the database and page encoding are gbk, the encoding here is ansi. if the database and page encoding are UTF-8, then UTF-8 is also used.
4. In addition, the data transmitted in Javascript or Flash is UTF-8 encoded. if the database and page encoding are gbk, transcode the data and write it to the database.
Iconv ('utf-8', 'gbk', $ content );
5. in the PHP program, you can add a line to specify the encoding of the PHP source program:
Header ('content-type: text/html; charset = gbk ');
Php page code
1. set encoding in the file header
@ Header ('content-type: text/html; charset = UTF-8 ′);
>?
2. no headers have been used to set unknown paths. What is the difference between it and browser viewing ??? [/Quote]
They all tell the browser what encoding is used to display the webpage. what is the difference? one is to send the original HTTP header, and nothing is left in the webpage. what you mean is to write it in the webpage.
First, if you do not write this in the webpage, sending the HTTP header will take effect.
Second, use the header () function to send the original HTTP header, which can contain more content. encoding is only one of them.
Third, in some cases, do not display any content on the webpage, but notify the browser of the encoding used for subsequent actions.
3
// This function determines whether a string is a Chinese character.
Function chkGB ($ str ){
If (preg_match ("/^ [". chr (0xa1). "-". chr (0xff). "] + $/", $ str )){
Return true;
} Else {
Return false;
}
}
// If (chkGB ')){
// Echo 'hao ';
//} Else {
// Echo "bad ";
//}
Function tep_limit_string ($ str_show, $ length, $ post_string = '... '){
$ Mn_curr = 0;
$ Str_output = ";
$ Str_show = trim ($ str_show );
For ($ I = 0; $ I
$ Str_tmp = substr ($ str_show, $ I, 1 );
// Echo [...]
Article: http://www.cnblogs.com/eshow/archive/2011/10/05/2199305.html