I am searching for it today. Program During UTF-8 correction, garbled characters are found in the generated UTF-8 format document. The original file
Create_html.aspCodeAs follows:
Copy code The Code is 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 of this Code is as follows. XML (UTF-8 format) reads text including Chinese characters and then outputs, but every output is garbled. This problem has plagued me for a long time, later, I solved the problem with the help of the classic Forum "Xiaohan" and "Xiao Xiaoyu". thanks to them.
Maybe I was wrong at the beginning. Now the correct code is modified as follows, and the code "Xiao Xiaoyu" is used to generate a new UTF-8 format document using the read content. The Code is as follows:
Copy code The Code is as follows: <% @ Language = "VBScript" codePage = "65001" %>
<% Response. codePage = 65001%>
<% Response. charset = "UTF-8" %>
<%
'Declarative Variables
Dim read_path, write_paht, content
'---- Reading file content ------------------------
Function readtextfile (filepath, charset)
Dim STM
Set STM = server. Createobject ("ADODB. Stream ")
STM. type = 1' adtypebinary, read by binary data
STM. mode = 3'admodereadwrite. Here, only 3 can be used. Other errors will occur.
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 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 and write. If this parameter is set to 2, an error is returned.
STM. charset = charset
STM. Open
STM. writetext filecontent
STM. savetofile filepath, 2 'adsavecreateoverwrite, overwrite if the file exists
STM. Flush
STM. Close
Set STM = nothing
End sub
'File path to be read
Read_path = server. mappath ("example. xml ")
'File path to write
Write_path = server. mappath ("example. asp ")
'Read File Content
Content = readtextfile (read_path, "UTF-8 ")
'Output the file to be read
Response. Write (content)
'Start writing
Call writetextfile (write_path, content, "UTF-8 ")
%>
This code is quite practical and useful for generating static pages in UTF-8 format. I have also noted some necessary explanations. Note that:
Copy code The Code is as follows: <% @ Language = "VBScript" codePage = "65001" %>
<% Response. codePage = 65001%>
<% Response. charset = "UTF-8" %>
Do not forget the lines of code on your page. Otherwise, the output is garbled.