asp检查文件编码是不是utf8
asp检查文件编码是不是utf8,vbs检查文件编码,比网上流行的要准确。支持没有BOM头的文件,大多数utf8也没有这个
Function read(path) '将Byte()数组转成String字符串 Dim ado, a(), i, n Set ado = CreateObject("ADODB.Stream") ado.Type = 1 : ado.Open ado.LoadFromFile path n = ado.Size - 1 ReDim a(n) For i = 0 To n a(i) = ChrW(AscB(ado.Read(1))) Next read = Join(a, "") End Function Function is_valid_utf8(ByRef input) 'ByRef以提高效率 Dim s, re Set re = New Regexp s = "[\xC0-\xDF]([^\x80-\xBF]|$)" s = s & "|[\xE0-\xEF].{0,1}([^\x80-\xBF]|$)" s = s & "|[\xF0-\xF7].{0,2}([^\x80-\xBF]|$)" s = s & "|[\xF8-\xFB].{0,3}([^\x80-\xBF]|$)" s = s & "|[\xFC-\xFD].{0,4}([^\x80-\xBF]|$)" s = s & "|[\xFE-\xFE].{0,5}([^\x80-\xBF]|$)" s = s & "|[\x00-\x7F][\x80-\xBF]" s = s & "|[\xC0-\xDF].[\x80-\xBF]" s = s & "|[\xE0-\xEF]..[\x80-\xBF]" s = s & "|[\xF0-\xF7]...[\x80-\xBF]" s = s & "|[\xF8-\xFB]....[\x80-\xBF]" s = s & "|[\xFC-\xFD].....[\x80-\xBF]" s = s & "|[\xFE-\xFE]......[\x80-\xBF]" s = s & "|^[\x80-\xBF]" re.Pattern = s is_valid_utf8 = (Not re.Test(input)) End Function
ASP,VBS检测文件编码是gb2312还是utf8
WScript.Echo CheckFileChar("D:\NewRoot\daili.com\default.asp") function CheckFileChar(fullpath) set objstream=createobject("adodb.stream") objstream.Type=1 : objstream.mode=3 objstream.open objstream.Position=0 objstream.loadfromfile fullpath bintou=objstream.read(2) If AscB(MidB(bintou,1,1))=&HEF And AscB(MidB(bintou,2,1))=&HBB Then CheckFileChar="utf-8" ElseIf AscB(MidB(bintou,1,1))=&HFF And AscB(MidB(bintou,2,1))=&HFE Then CheckFileChar="unicode" Else CheckFileChar="gb2312" End If objstream.close : set objstream=nothing end function
Mysql命令方式导入导出时应指定编码
页码 1 / 11