×

UTF-8 bom

去除UTF-8格式签名(BOM)的asp函数

管理员 管理员 发表于2010-02-21 16:19:56 浏览3227 评论0

抢沙发发表评论

UTF-8签名(UTF-8 signature)也叫做BOM(Byte Order Mark),是UTF编码方案里用于标识编码的标准。如果多个文件设置了签名,在二进制流中就会包含多个UTF-8签名,而IE是无法识别多个UTF-8 签名的,所以用一个空行来代替,在某些程序处理中还会出现一个类似“诺”的字符。

以下为去除Utf-8格式签名的asp函数:
Function RemoveUtf8Bom(filePath)
        Dim oStream,oDom,oDomFile,newStream
        Set oStream = Server.CreateObject("adodb.stream")
        With oStream
            .Type = 1
            .Open()
            .LoadFromFile filePath
        End With
        Set oDom = Server.CreateObject("Microsoft.XMLDOM")
        Set oDomFile = oDom.CreateElement("file")
        With oDomFile
            .dataType = "bin.base64"
            .nodeTypedValue = oStream.Read(3)
        End With
        If oDomFile.Text = "77u/" Then
            oStream.Position = 3
            Set newStream = Server.CreateObject("adodb.stream")
            With newStream
                .Mode = 3
                .Type = 1
                .Open()
            End With
            oStream.CopyTo(newStream)
            newStream.SaveToFile filePath,2
        End If
        Set oStream = Nothing
        Set newStream = Nothing
        Set oDomFile = Nothing
        Set oDom = Nothing
End Function

群贤毕至

访客