The solution to garbled characters when using fso.OpenTextFil to read UTF-8 files or using FSO.save to generate UTF-8 files. The method used to generate static pages is to read the html code of the asp page and save it as an html file. This method
Since the dynamic page is encoded in utf8 format, after I got its html code, I used fso to save it. The generated html was successful, but it cannot be accessed because there is a problem with the html encoding. Select gb2312 and you can access it normally. This won't work, because the entire site is encoded in utf8 format. To open this page, you need to select the encoding before accessing it. This is too troublesome, and no one is willing to access it, so the utf8 format encoding problem must be solved.
After some searching, I discovered that fso cannot generate files in utf8 format. So try another approach.
After searching for a while, I found a function that can generate files instead of fso. It uses the adodb.stream object to generate utf8 files. The function is as follows:
Copy the code code as follows:
'------------------------------------------------
'Function name: ReadTextFile
'Function: Use the AdoDb.Stream object to read text files in UTF-8 format
'------------------------------------------------ ---
Function ReadFromTextFile (FileUrl,CharSet)
dim str
set stm=server.CreateObject("adodb.stream")
stm.Type=2 'Read in this mode
stm.mode=3
stm.charset=CharSet
stm.open
stm.loadfromfile server.MapPath(FileUrl)
str=stm.readtext
stm.Close
set stm=nothing This article comes from
ReadFromTextFile=str
End Function
'------------------------------------------------
'Function name:WriteToTextFile
'Function: Use the AdoDb.Stream object to write text files in UTF-8 format
'------------------------------------------------ ---
Sub WriteToTextFile (FileUrl, byval Str, CharSet)
set stm=server.CreateObject("adodb.stream")
stm.Type=2 'Read in this mode
stm.mode=3
stm.charset=CharSet
stm.open
stm.WriteText str
stm.SaveToFile server.MapPath(FileUrl),2
stm.flush
stm.Close
set stm=nothing
End Sub IISBOY.COM,IISBOY.COM
How to use:
Copy the code code as follows:
call WriteToTextFile ("../index.html","aaa","utf-8")
Done.