日期:2014-05-16  浏览次数:20772 次

fso生成utf8后乱码问题
本帖最后由 mycilent 于 2012-12-05 02:02:34 编辑

Set fso = Server.CreateObject("Scripting.FileSystemObject")

qvoddir=server.mappath("/qvod/")
If not fso.folderexists(qvoddir) then   
fso.createfolder(qvoddir)  
Response.write "创建文件夹--"&qvoddir
End if 

set myCache=new cache
myCache.name="qvodtemp"
set fr=fso.opentextfile(server.mappath("moban/qvod.htm"))
pencat=fr.readall
fr.close
myCache.add pencat,dateadd("h",3,Now)

pencat=replace(pencat,"{$title}",title)

Set fout = fso.CreateTextFile(server.mappath("/play/"&id&".htm"),true,1)
fout.Write pencat
fout.close


代码生成utf8后总是有乱码,前面的fso.CreateTextFile()没加参数生成后也没出新乱码情况。

模板已用dw转为utf8编码格式,页面已加上了 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
直接用浏览器打开模板文件没出现乱码,
数据库里面的内容生成后不是乱码,生成后变成乱码的字就是那些直接在模板里面写的汉字。

求教下这么解决这个乱码,网上说adodb.stream可以生成utf8编码的,该怎么写啊。
------解决方案--------------------
fso无法生成utf-8文件的。
要使用:adodb.stream对象
看这里:http://www.aspbc.com/tech/showtech.asp?id=379
------解决方案--------------------
'*************************************************
'=使用说明:保存指定内容为UTF-8文件 file:相对绝对地址
'*************************************************
Sub Save_File(byval strbody,byval file)
On Error Resume Next
dim objstream
Set objstream = Server.Createobject("adodb.stream")
If err.number=-2147221005 Then 
Response.Write "<script>alert('您的主机不支持adodb.stream!无法保存["&file&"]文件!');history.back();</div>"
err.clear
Set objstream = Noting
Exit Sub
response.end
End If
With objstream
.type = 2
.open
.charset = "utf-8"
.position = 0
.writetext = strbody
.savetofile server.mappath(file),2
.close
End With
Set objstream = Nothing
End Sub
//....省略
pencat=replace(pencat,"{$title}",title)
Call Save_File(pencat,"/play/"&id&".htm")
'Set fout = fso.CreateTextFile(server.mappath("/play/"&id&".htm"),true,1)
'fout.Write pencat
'fout.close