Today in the search for the program to Utf-8 correction, found that the generated Utf-8 format documents are garbled, the original file
The create_html.asp code is as follows:
Copy Code code as follows:
<% @LANGUAGE = "VBSCRIPT" codepage= "65001"%>
<%
Set Objrs=server.createobject ("Scripting.FileSystemObject")
Conn=server.mappath ("Example.xml")
Set Stream=objrs.opentextfile (conn,1,true,-2)
Content=stream.readall
Response.Write (content)
Stream.Close
%>
The function to implement this code is: read the text from Example.xml (utf-8 format) including Chinese, and then output, but each output is garbled, this problem really bothered me for a long time, and later still in the classic forum, "Xiao Han" "Rustling Rain" to solve the help, really thank them.
Maybe I was wrong in the beginning, and now the correct code is modified to use the "rustling" code, including the use of read content to generate new Utf-8 format documents. The detailed code is as follows:
Copy Code code as follows:
<% @LANGUAGE = "VBSCRIPT" codepage= "65001"%>
<% response.codepage=65001%>
<% response.charset= "UTF-8"%>
<%
' Declare the variable
Dim read_path,write_paht,content
'----Read the contents of the file------------------------
Function ReadTextFile (Filepath,charset)
Dim stm
Set Stm=server.createobject ("ADODB.stream")
Stm. Type=1 ' adTypeBinary, read in binary data
Stm. Mode=3 ' adModeReadWrite, there's only 3 to use.
Stm. Open
Stm. LoadFromFile FilePath
Stm. Position=0 ' Move the pointer back to the starting point
Stm. type=2 ' Text data
Stm. Charset=charset
ReadTextFile = stm. ReadText
Stm. Close
Set stm=nothing
End Function
'----Write to file------------------------
Sub WriteTextFile (Filepath,filecontent,charset)
Dim stm
Set Stm=server.createobject ("ADODB.stream")
Stm. type=2 ' adTypeText, text data
Stm. Mode=3 ' adModeReadWrite, read write, this parameter with 2 error
Stm. Charset=charset
Stm. Open
Stm. WRITETEXT filecontent
Stm. SaveToFile filepath,2 ' adsavecreateoverwrite, file exists to overwrite
Stm. Flush
Stm. Close
Set stm=nothing
End Sub
' The file path to read
Read_path = Server.MapPath ("Example.xml")
' The file path to write to
Write_path = Server.MapPath ("example.asp")
' Read the contents of the file
Content = ReadTextFile (Read_path, "Utf-8")
' Output read files
Response.Write (content)
' Start writing
Call WriteTextFile (write_path,content, "Utf-8")
%>
This code is quite practical, useful for generating static pages in utf-8 format, and some of the necessary explanations are noted:
Copy Code code as follows:
<% @LANGUAGE = "VBSCRIPT" codepage= "65001"%>
<% response.codepage=65001%>
<% response.charset= "UTF-8"%>
Your page do not forget these lines of code, or you read the output after the content is garbled.