I. HTML page to UTF-8 encoding problem 1. after the head, add a line before the title: metahttp-equivContent-Typecontenttexthtml; charsetutf-8 order cannot be wrong, be sure to display the title may be garbled! 2.html file encoding: Click the Editor menu: "file"-"Save as". You can see
I. HTML page to UTF-8 encoding problem 1. after the head, add a line before the title: meta http-equiv = 'content-type' Content = 'text/html; charset = UTF-8 '/the order cannot be wrong, the title displayed must be garbled! 2.html file encoding: Click the Editor menu: "file"-"Save as". You can see
I. HTML page to UTF-8 encoding problem
1. Add a line before the title after the head:
The order must be in
The title may be garbled!
2.html file encoding:
Click the Editor menu: "file"-> "Save as", you can see the current file encoding, make sure the file encoding: UTF-8,
If it is ANSI, you need to change the encoding to: UTF-8.
3. HTML file header BOM:
2. You can open the file with EditPlus and choose "Preferences"> "Files"> "UTF-8 identifier" from the menu to "always remove signature ",
4. WEB Server UTF-8 coding problems:
If you follow the steps listed above, there are still Chinese garbled characters,
Check the encoding of your WEB server.
If you are using Apache, set charset in the configuration file to UTF-8 (only the method is listed here. For the specific format, refer to the apache configuration file)
If you are using Nginx, set charset in nginx. conf to UTF-8,
Find "charset gb2312;" or a similar statement and change it to "charset UTF-8 ;".
2. PHP page to UTF-8 encoding problem
1. Add a line at the beginning of the Code:
header("Content-Type: text/html;charset=utf-8");
2. php file Encoding Problems
Click the Editor menu: "file"-> "Save as", you can see the current file encoding, make sure the file encoding: UTF-8,
If it is ANSI, you need to change the encoding to: UTF-8.
3. php file header BOM problems:
Otherwise, the session cannot be used, and a similar prompt is displayed:
Warning: session_start () [function. session-start]: Cannot send session cache limiter-headers already sent
2. You can open the file with EditPlus and choose "Preferences"> "Files"> "UTF-8 identifier" from the menu to "always remove signature ",
4. UTF-8 coding problems when PHP saves files in the form of attachments:
PHP saves the file as an attachment. The file name must be GB2312 encoded,
Otherwise, if the file name contains Chinese characters, garbled characters will be displayed:
If your PHP is a UTF-8-encoded file,
You need to convert the file name variable from UTF-8 to GB2312:
Iconv ("UTF-8", "GB2312", "$ filename ");
5. Garbled text or "?" appears when the title of the document is truncated. Question mark:
When the title of an article is very long, a part of the title will be displayed and the title will be truncated,
Since a Chinese character in UTF-8 encoding format occupies 3 Characters in width,
When you intercept a title, it is sometimes only one or two characters in width of a Chinese character,
If the screenshot is not complete, garbled characters or "?" may occur. Question mark,
You can use the following function to extract the title:
function get_brief_str($str, $max_length){echo strlen($str) ."
";if(strlen($str) > $max_length){$check_num = 0;for($i=0; $i < $max_length; $i++){if (ord($str[$i]) > 128)$check_num++;}if($check_num % 3 == 0)$str = substr($str, 0, $max_length)."...";else if($check_num % 3 == 1)$str = substr($str, 0, $max_length + 2)."...";else if($check_num % 3 == 2)$str = substr($str, 0, $max_length + 1)."...";}return $str;}
Iii. Problem of using UTF-8 encoding in MYSQL database
1. Use phpmyadmin to create databases and data tables
When creating a database, set "sorting" to "utf8_general_ci"
Or execute the statement:
CREATE DATABASE `dbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
When creating a data table: If this field is used to store Chinese characters, set "sorting" to "utf8_general_ci ",
This field can be used by default if it is an English or number.
The corresponding SQL statement, for example:
CREATE TABLE `test` (`id` INT NOT NULL ,`name` VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,PRIMARY KEY ( `id` )) ENGINE = MYISAM ;
2. Use PHP to read and write Databases
After connecting to the database:
[Hide] $ connection = mysql_connect ($ host_name, $ host_user, $ host_pass );
Add two rows:
Mysql_query ("set character set 'utf8'"); // read database mysql_query ("set names 'utf8'"); // write Database
You can read and write the MYSQL database normally.
4. JS-related UTF-8 coding problems
1. Chinese garbled characters for reading cookies in JS
When writing cookies in PHP, You need to encode the Chinese characters in escape,
Otherwise, Chinese characters in the cookie read by JS will be garbled.
However, php itself does not have the escape function. We will write a new escape function:
function escape($str){preg_match_all("/[\x80-\xff].|[\x01-\x7f]+/",$str,$r);$ar = $r[0];foreach($ar as $k=>$v){if(ord($v[0]) < 128)$ar[$k] = rawurlencode($v);else$ar[$k] = "%u".bin2hex(iconv("UTF-8","UCS-2",$v));}return join("",$ar);}
When JS reads cookies, it uses unescape to decode them,
Then, the problem of Chinese garbled characters in cookies is solved.
2. External JS file UTF-8 coding problem
When an HTML page or a PHP page contains an external JS file,
If an HTML page or a PHP page is an UTF-8-encoded file,
External JS files also need to be converted into UTF-8 files,
Otherwise, the system prompts that none of them are unsuccessful and no response is made when the function is called.
Click the Editor menu: "file"-> "Save as", you can see the current file encoding, make sure the file encoding: UTF-8,
If it is ANSI, you need to change the encoding to: UTF-8.
5. UTF-8 coding problems related to FLASH
FLASH internally treats all strings with UTF-8 by default
1. FLASH reader (txt, html)
To encode a text file into a UTF-8
Click the Editor menu: "file"-> "Save as", you can see the current file encoding, make sure the file encoding: UTF-8,
If it is ANSI, you need to change the encoding to: UTF-8.
2. Read XML files in FLASH
To encode an XML file into a UTF-8
Click the Editor menu: "file"-> "Save as", you can see the current file encoding, make sure the file encoding: UTF-8,
If it is ANSI, you need to change the encoding to: UTF-8.
Write in XML 1st lines:
3. data returned by FLASH reading PHP
If PHP encoding itself is UTF-8, just echo it.
If PHP encoding itself is GB2312, you can convert PHP into UTF-8 encoding format file, direct echo can be
If PHP encoding is GB2312 and the file encoding format cannot be changed,
Use the following statement to convert the string to the encoding format of the UTF-8
$ New_str = iconv ("GB2312", "UTF-8", "$ str ");
Echo again.
4. read data from the FLASH database (MYSQL)
FLASH needs to read data from the database through PHP
PHP encoding is not important. The key is that if the database encoding is GB2312,
You need to use the following statement to convert the string to the encoding format of the UTF-8
$ New_str = iconv ("GB2312", "UTF-8", "$ str ");
5. FLASH writes data through PHP
In a word, the FLASH string is in UTF-8 format,
To convert to the corresponding encoding format, perform operations (write files, write databases, direct display, etc)
Still use iconv Function Conversion
6. FLASH uses local encoding (not recommended theoretically)
If you want FLASH to use local encoding instead of UTF-8 encoding
For Mainland China, the local code is GB2312 or GBK.
In the AS program, you can add the following code:
System. useCodepage = true;
All the characters in FLASH are encoded in GB2312.
All data imported to or exported from FLASH must be encoded and converted accordingly.
Because local encoding is used, garbled characters are generated for users in Traditional Chinese, so it is not recommended to use