网页中的字符编码(html的unicode实体编码)
2012-02-04 21:11
190 查看
1、编码转换(to Unicode)(程序代码来源于网络)Js版 <script> test = "你好abc" str = "" for( i=0; i<test.length; i++ ) { temp = test.charCodeAt(i).toString(16); str += "\\u"+ new Array(5-String(temp).length).join("0") +temp; } document.write (str) </script> vbs版 Function Unicode(str1) Dim str,temp str = "" For i=1 to len(str1) temp = Hex(AscW(Mid(str1,i,1))) If len(temp) < 5 Then temp = right("0000" & temp, 4) str = str & "\u" & temp Next Unicode = str End Function Function htmlentities(str) For i = 1 to Len(str) char = mid(str, i, 1) If Ascw(char) > 128 then htmlentities = htmlentities & "" & Ascw(char) & ";" Else htmlentities = htmlentities & char End if Next End Function coldfusion版 function nochaoscode(str) { var new_str = “”; for(i=1; i lte len(str);i=i+1){ if(asc(mid(str,i,1)) lt 128){ new_str = new_str & mid(str,i,1); }else{ new_str = new_str & “#” & asc(mid(str,i,1)); } } return new_str; } 附: 在php中我们可以用mbstring的mb_convert_encoding函数实现这个正向及反向的转化。 如: mb_convert_encoding ("你好", "HTML-ENTITIES", "gb2312"); //输出:你好 mb_convert_encoding ("你好", "gb2312", "HTML-ENTITIES"); //输出:你好 如果需要对整个页面转化,则只需要在php文件的头部加上这三行代码: mb_internal_encoding("gb2312"); // 这里的gb2312是你网站原来的编码 mb_http_output("HTML-ENTITIES"); ob_start('mb_output_handler'); 如果没有打开mbstring扩展,可以参考coolcode.cn上的这两篇文章: 在任意字符集下正常显示网页的方法 在任意字符集下正常显示网页的方法(续) 2、HTML实体HTML 4.01 支持 ISO 8859-1 (Latin-1) 字符集。提示 实体名是区分大小写的。 备注 同一个符号,可以用“实体名称”和“实体编号”两种方式引用,“实体名称”的优势在于便于记忆,但不能保证所有的浏览器都能顺利识别它,而“实体编号”则没有这种担忧,但它实在不方便记忆。 [align=center][/align] ASCII中部分实体的新名字
|
相关文章推荐
- java 中转换html 实体编码为汉字---unicode编码(\u)、十进制(&#)、十六进制(&#x)
- html网页编码设置导致jsp页面乱码
- Python处理HTML实体编码
- python unicode 转中文 遇到的问题 爬去网页中遇到编码的问题
- HTML实体编码
- 对于Unicode编码在js中和html中
- 字符编码知识:Unicode、UTF-8、ASCII、GB2312等编码之间是如何转换的?
- ANSI,Unicode,UTF-8网页编码的区别【转】
- 网页HTML特殊符号代码大全,HTML特殊字符编码对照表
- javascript和html中unicode编码和字符转义的详解
- 字符编码(ASCII、ANSI、UNICODE及UTF-8编码)
- 刨根究底字符编码之十——Unicode字符集的编码方式以及码点、码元
- 字符编码知识:Unicode、UTF-8、ASCII、GB2312等编码之间是如何转换的?
- class编码与字符编码格式小结(ASCII/Unicode/UTF-8)
- 关于HTML网页源码的字符编码(charset)格式(GB2312,GBK,UTF-8,ISO8859-1等)的解释
- 有关保存文件时的编码选项与html/jsp页面设定字符编码的配置
- Unicode编码识别HTML中的转义字符------字符解析表
- 字符编码知识:Unicode、UTF-8、ASCII、GB2312等编码之间是如何转换的?[转]
- android之html Unicode编码转汉字
- 字符编码知识:Unicode、UTF-8、ASCII、GB2312等编码之间是如何转换的?