Now a lot of Chinese websites are encoded in from gb2312 to Utf-8 code conversion. There are a number of problems here to summarize:
Premise:
Ensure that all files are UTF-8 encoded, not ANSI, when they are saved
Settings: If you are using a text editor, there is an encoding option when you save the file (Figure 1) and select it as UTF-8.
If you're using Dreamweaver then it's a bit of a hassle.
When you use Dreamweaver to edit a static file, modify the file's CharSet label to Utf-8:
change to
and then choose Save as this time dream will save the file as Utf-8 encoded
Note: If you are using an Access database, you only need the above two steps, and access itself uses UTF-8 encoding.
ASP article
code page settings:
The first line of the ASP file:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
Change to:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
It also directly determines the encoding that ASP uses to access the database through ADO.
Note: If you are using an Access database, you only need the above two steps, and access itself uses UTF-8 encoding.
If you use a template program
The usual template program, through the FSO object to read and write files. But this is not a way to support utf-8, you need to change to a stream object to read and write files, here are a few lines of key code:
Read files using Stram
Set objStream = Server.CreateObject("ADODB.Stream")
With objStream
.Open
.Charset = "utf-8"
.Position = objStream.Size
.LoadFromFile server.mappath("sc.htm")
wstr = .ReadText
.Close
End With
Set objStream = Nothing
Write a file using stream
Set objStream = Server.CreateObject("ADODB.Stream")
With objStream
.Open
.Charset = "utf-8"
.Position = objStream.Size
.WriteText=wstr
.SaveToFile server.mappath("wz/sc_" & classid & ".htm"),2
.Close
End With
Set objStream = Nothing
PHP article
PHP Connects to access:
COM extensions that use PHP on Windows hosts can connect to an Access database and specify a code page parameter of 65001 when establishing adodb.connection
$conn = new COM("ADODB.Connection",NULL,65001) or die("ADO connect failed!");
$rs = new COM("ADODB.RecordSet") or die("ADO recordset fail"); $conn->open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb");
$rs = $conn->Execute("select * from data");
while not $rs->EOF
echo $rs->Fields['title']->value;
?>
PHP connection with MySQL
After establishing a connection to the MySQL database, execute the following SQL query first:
MySQL manual about set names set names shows what character set is used in the SQL statement sent by the client. Therefore, the set NAMES ' cp1251 ' statement tells the server that "the information coming from this client will be in character set cp1251". 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.) )
The SET NAMES ' x ' statement is equivalent to these three statements:
mysql> SET character_set_client = x;
mysql> SET character_set_results = x;
mysql> SET character_set_connection = x;
Setting X to Character_set_connection also sets Collation_connection as the default proofing rule for X.
Use the ADODB class:
Set the ' Charpage ' property to 65001;
require_once('adodb/adodb.inc.php');
$conn =& ADONewConnection('ado_access');
$conn->charPage ='65001';
//$conn->charPage = 65001;
//$conn->debug = true;
$dsn = sprintf("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= %s",realpath('2data.mdb'));
// $dsn = sprintf("Driver={Microsoft Access Driver (*.mdb)};Dbq=%s",realpath("data.mdb"));
$conn->Connect($dsn);