最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
检测文件编码的asp代码
时间:2010-08-31 编辑:简简单单 来源:一聚教程网
ansi的本地编码,都是各国自己定义的,没有固定的文件头格式,在大陆中文操作系统下,是可读的gb2312,在其他语言的系统下,就是乱码,所以这部分没必要再详细区分。
ansi:无格式定义
unicode:前两个字节为fffe
unicode big endian:前两字节为feff
utf-8:前两字节为efbb
function checkcode(path)
set objstream=server.createobject("adodb.stream")
objstream.type=1
objstream.mode=3
objstream.open
objstream.position=0
objstream.loadfromfile path
bintou=objstream.read(2)
if ascb(midb(bintou,1,1))=&hef and ascb(midb(bintou,2,1))=&hbb then
checkcoder="utf-8"
elseif ascb(midb(bintou,1,1))=&hff and ascb(midb(bintou,2,1))=&hfe then
checkcode="unicode"
else
checkcode="gb2312"
end if
objstream.close
set objstream=nothing
end function
原理:用stream对象预读文件的头两个字节,分析判断出utf-8、unicode、ansi(简体中文操作系统,即gb2312)编码。
-
上一个: 操作Excel的asp程序代码
-
下一个: asp 获取字符串中url地址函数
相关文章
- asp检测文件编码 05-04
- VBS 批量Ping的项目讲解 09-19
- 如何封装一个Ajax函数介绍 09-16
- ASP实现加法验证码方法 09-16
- ASP错误捕获的几种常规处理方法介绍 09-16
- ajax实现城市三级联动的代码介绍 09-16