|
蓝森林 http://www.lslnet.com 2006年8月25日 8:28
utf-8 字符串转换的问题
我的页子使用了utf-8编码。里面要做一个小功能,同主题搜索(百度,google)
[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<a href="#" onclick="window.open('http://www.baidu.com/s?wd=你好')">百度</a><br><br><br>
<a href="#" onclick="window.open('http://www.google.com/search?hl=zh-CN&q=你好')">谷歌</a><br>
</body>
</html>
[/code]
这个文件用 editplus 另存为 utf-8 格式,双击打开html文件,点击“百度”链接,能正确地搜索。如果把此html文件放到iis中访问,则百度搜索“你好”时乱码了,但此时google正常。
分析了baidu与google的代码,发现前者使用了gb2312后者使用了utf-8,我的页子也使用了utf-8,怎么在我的页子上搜索“你好”时不乱码?
这是在windows 2003(iis6.0)下面的效果:
[url=http://www.happyshow.org/sample/20060804/utf8.html]http://www.happyshow.org/sample/20060804/utf8.html |
在百度的你好后跟一个ie=gb2312参数即可
[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<a href="#" onclick="window.open('http://www.baidu.com/s?wd=你好&ie=gb2312')">百度</a><br><br><br>
<a href="#" onclick="window.open('http://www.google.com/search?hl=zh-CN&q=你好')">谷歌</a><br>
</body>
</html>
[/html] |
后来发现 这种方法其实不好用,后来发现把你好改为%C4%E3%BA%C3就可以了,这是个UrlEncode |
用 server.UrlEncode("你好") 还是不行。。。。。
[url=http://www.happyshow.org/sample/20060804/utf8.asp]http://www.happyshow.org/sample/20060804/utf8.asp
|
好像解码不同:server.UrlEncode的解码是%E4%BD%A0%E5%A5%BD
百度的解码是(就是在百度上查询时地址栏上的关键词解码)是%C4%E3%BA%C3
而且好像只有%C4%E3%BA%C3好用,我也郁闷中... |
轻轻一顶~ |
server.urlEncode("你好") 编码是%C4%E3%BA%C3 ,你的怎么出来的? |
晕,给百度加上ie=utf-8不就完了
[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<a href="#" onclick="window.open('http://www.baidu.com/s?wd=你好&ie=utf-8')">百度</a><br><br><br>
<a href="#" onclick="window.open('http://www.google.com/search?hl=zh-CN&q=你好')">谷歌</a><br>
</body>
</html>[/code]
|
|