分享

写回答

发帖

[提问] ASP读取服务器上的txt文件显示乱码,求解决方法

GoDaddy GoDaddy 3124 人阅读 | 10 人回复

发表于 2010-8-3 00:24:40 | 显示全部楼层 |阅读模式

说明三点:
1、txt文件下载到电脑里完全可以正常查看
2、已经测试了把txt另存为所有的编码格式
3、程序是调用服务器上的TXT文件,读取文件内容,前台输出显示。
乱码截图如下:
QQ截图未命名.png


相关代码:
<!--#include file="const.asp"-->

<%Function main
        dim rs,sql,i,id,PageCount,Page,PageOut,PageIn,PageSize,content,classid,RepCount,gm,viphy,nid,read,readtime

        PageSize=500

        id=Request.QueryString("id")
        if id="" then id=0
        if not isnumeric(id) then id=0
        id=clng(id)

            Page = Request("page")      '当前页数
            If Page = "" Then Page = 1
           If Not IsNumeric(Page) Then Page = 1
            Page = CLng(Page)
            If Page < 1 Then Page = 1


        if xy<>"Null" then

        Set Rs = Server.CreateObject("Adodb.Recordset")

        Sql = "select vip,id from xywap_user where xy='"&md5(xy) & md5(strReverse(xy))&"'"
        Rs.Open Sql,conn,1,1

        if not (rs.bof and rs.eof)  then
                viphy=rs("vip")
                nid=rs("id")
        end if
        Rs.close       

        Sql = "select id from xywap_goumai where ext=2 and listid="&id&" and  nid="&nid&""
        Rs.Open Sql,conn,1,1
        if not (rs.bof and rs.eof)  then
                gm=1
        else
                gm=0
        end if
        Rs.close       

        set rs=nothing
        else
                viphy=0
                gm=0
        end if



        conn.execute("update xywap_view_list set ReadCount=ReadCount+1 where id="&id&"")

        Set Rs = Server.CreateObject("Adodb.Recordset")

        Sql = "select name,classid,Urls,zuozhe,laiyuan,RepCount,ReadCount,[WriteTime],[readtime],tuijian,vip,zf,viphy,vipgm from xywap_view_list where id="&id
        Rs.Open Sql,conn,1,1
        if not (rs.bof and rs.eof)  then

                readtime=rs("readtime")

                Dim path,FsoObj,tempfileOBJ,txt
                Path = server.mappath(Request.ServerVariables("SCRIPT_NAME"))
                Path=left(Path,instrrev(Path,"\" ) - 1 )
                path=Path & "/" & RS("urls")

                    Set FsoObj=Server.CreateObject("Scripting.FileSystemObject")
                IF FSOObj.FileExists(path) = True then
                   Set tempfileOBJ = FsoObj.OpenTextFile(path, 1, 0, 0 )
                    While NOT tempfileOBJ.AtEndOfStream
                        txt=txt & tempfileOBJ.ReadLine & vbNewLine
                    Wend
                Set tempfileOBJ=Nothing
                end if
                Set FsoObj=Nothing
                if len(txt)>2 then txt=trim(left(txt,len(txt)-2))


                if viphy=1 then
                        if rs("vipgm")=1 then
                                if gm=1 then
                                        read=true
                                else
                                        read=false
                                end if

                        else
                                read=true
                        end if
                elseif rs("viphy")=1 then
                        read=false
                elseif rs("vip")=1 then
                                if gm=1 or rs("zf")=0 then
                                        read=true
                                else
                                        read=false
                                end if
                else
                        read=true

                end if

                RepCount=rs("RepCount")
                classid=rs("classid")
                content=txt
                if Request.QueryString("act")<>1 then
               

                ''''''''''''''''''智能分页''''''''''''''''''''''
                      Dim  n
                I = 1
                Do
                    n = n + 1
                    If n = page Then
                        PageIn = I
                   End If
                    If InStr(I, content, "

回答|共 10 个

北极末端

发表于 2010-8-3 08:53:54 | 显示全部楼层

人都跑哪去了?

cqboy2003

发表于 2010-8-3 08:58:57 | 显示全部楼层

乱码一般来说是因为编码问题

add.c

发表于 2010-8-3 09:13:45 | 显示全部楼层

把你的txt文本 另存为utf-8编码即可
RAKSmart

北极末端

发表于 2010-8-3 09:28:14 | 显示全部楼层

回复 4# 的帖子

已经测试了把txt另存为所有的编码格式
包括utf-8

add.c

发表于 2010-8-3 10:53:27 | 显示全部楼层

如果可能的话你看看能否换一种方法,
或者在存取的时候指定编码?

北极末端

发表于 2010-8-3 14:33:28 | 显示全部楼层

回复 6# 的帖子

指定为什么编码呢?

add.c

发表于 2010-8-3 15:25:03 | 显示全部楼层

回复 7# 的帖子

我对编程不熟悉只是提供下思路

看能否指定为utf-8编码的?
其实简单的方法是你试试其他程序看有可以正常的没,若有, 参考他们的代码

北极末端

发表于 2010-8-3 16:06:42 | 显示全部楼层

回复 8# 的帖子

刚测试完,生产txt文件的时候直接生产utf-8格式的,一样是乱码一堆,能否叫空间商安装中文语言包呢?

add.c

发表于 2010-8-3 17:06:30 | 显示全部楼层

回复 9# 的帖子

他们不会帮你安装, 只能考虑修改程序
能否换一种方法读取呢, 比如ado
您需要登录后才可以回帖 登录 | 注册

本版积分规则