Home > Article > Web Front-end > From gb to utf-8_experience exchange
Now the encoding of many Chinese websites is converting from gb2312 to utf-8 encoding. There are many problems that arise and are summarized here:
Ensure that all files are saved in UTF-8 encoding, not ANSI
Specific settings: If you are using a text editor, there is an encoding selection when saving the file (Figure 1) Just select it as UTF-8.
If you are using Dreamweaver, it will be a little more troublesome.
When using Dreamweaver to edit static files, change the charset tag of the file to utf-8: <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
to <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
and then select Save As. Dream will save the file as utf-8 encoded
Note: If you are using the access database, you only need the above two steps. Access itself uses UTF-8 encoding.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
changed to: <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
This also directly determines the encoding used by ASP to access the database through ADO. Set objStream = Server.CreateObject(" ADODB.Stream") <code>Set objStream = Server.CreateObject("ADODB.Stream") <br> With objStream <br> .Open <br> .Charset = "utf-8" <br> .Position = objStream.Size <br> .LoadFromFile server.mappath("sc.htm")<br> wstr = .ReadText<br> .Close <br> End With <br>Set objStream = Nothing<br>
With objStream Set objStream = Server.CreateObject("ADODB.Stream") <br> With objStream <br> .Open <br> .Charset = "utf-8" <br> .Position = objStream.Size <br> .WriteText=wstr <br> .SaveToFile server.mappath("wz/sc_" & classid & ".htm"),2 <br> .Close <br> End With <br>Set objStream = Nothing
.Open .Close
End With<?php<BR>$conn = new COM("ADODB.Connection",NULL,65001) or die("ADO connect failed!");<BR>$rs = new COM("ADODB.RecordSet") or die("ADO recordset fail"); $conn->open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb"); <br>$rs = $conn->Execute("select * from data");<br>while not $rs->EOF<br>echo $rs->Fields['title']->value;<br>?>
Set objStream = NothingUse stream to write files
Set objStream = Server.CreateObject("ADODB.Stream" ) With objStream <p> .Open </p> .Charset = "utf-8" <code><?php mysql_query("SET NAMES 'utf8'"); ?>
.Position = objStream.Size .WriteText=wstr .SaveToFile server.mappath("wz/ sc_" & classid & ".htm"),2 End With Set objStream = Nothing
php article
Use the COM extension of PHP on the Windows host to connect to the access database. When establishing ADODB.Connection, specify the code page parameter as 65001<?php<BR>$conn = new COM(" ADODB.Connection",NULL,65001) or die("ADO connect failed!");</P>$rs = new COM("ADODB.RecordSet") or die("ADO recordset fail"); $conn-> open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb");
while not $rs ->EOF
echo $rs->Fields['title']->value;After establishing a connection with the mysql database, first execute the following SQL query:
<?php<BR>require_once('adodb/adodb.inc.php'); <BR>$conn =& ADONewConnection('ado_access'); <BR>$conn->charPage ='65001';<br>//$conn->charPage = 65001;<br>//$conn->debug = true;<br>$dsn = sprintf("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= %s",realpath('2data.mdb'));<br>// $dsn = sprintf("Driver={Microsoft Access Driver (*.mdb)};Dbq=%s",realpath("data.mdb"));<br>$conn->Connect($dsn);
mysql manual Description of set names SET NAMES displays what character set is used in the SQL statement sent by the client. Therefore, the SET NAMES 'cp1251' statement tells the server that "future information from this client will use character set cp1251." It also specifies the character set for the results that the server sends back to the client. (For example, if you use a SELECT statement, it indicates what character set is used for the column values.) The SET NAMES 'x' statement is equivalent to these three statements:
mysql> SET character_set_client = x;
Use adodb class:
Set the 'charpage' attribute to 65001; <?php<🎜>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);