求助:UTF-8

  由于我的空间提供商的默认编码是gb2312,所以我建立的html文件在浏览器下都自动作为gb2312显示,但是我想使用的是utf-8编码,如何实现呢?我在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” xml:lang=”zh_CN” lang=”zh_CN”>
<head profile=”http://gmpg.org/xfn/11″>
<title>Title</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />

  我查看过WP的源代码,它的header就是如此写得,但是为什么WP可以正常的显示utf-8,但是我做的html却不可以?另外我记得wp1.2之前也是不能正常显示的,从wp1.5开始却正常了。

21 Responses to “求助:UTF-8”

  • Hui says:

    你是通过什么来编辑这些html文件的?确定你编辑的时候以UTF8保存了?

    给一个你写的html文件的例子?

  • kDolphin says:

    其实是Blogger.com发布的模版,我也能确定文件本身是utf-8编码的。

  • jtam says:

    Try php, 可能你的ISP在发送html的时候往header里面加东西了,用php直接输出来看看~

  • hsuyo says:

    試試把 meta 那行移到 title 上面
    也就是在 <head></head> 內的第一行放入 meta 標籤

  • Platinum says:

    1. 一定要在 之前

    Title

    2. WP 没用过,可能是因为程序在显示页面之前发送的 http header 里定义了字符集,对于 IE 来说,这里指定的字符集优先级高于页面里 定义的

  • Platinum says:

    不是吧?!你的 comment 居然不关闭 html ……

    测试一下

  • Platinum says:

    〈meta charset〉一定要在〈title〉之前

    〈meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ /〉
    〈title〉Title〈/title〉

  • virushuo says:

    我访问你这里,就是默认utf-8的啊

  • kDolphin says:

    加在title前面也不行,可以访问这里看效果
    http://www.kdolphin.org/blogger/
    这是由blogger发布的,都是静态的html文件。

  • Anonymous says:

    是web server把编码方式设定为gb2312,所以在http响应的信息头如下:
    Wed Oct 12 15:09:01 2005 HTTP/1.1 200 OK
    Wed Oct 12 15:09:01 2005 Connection: close
    Wed Oct 12 15:09:01 2005 Content-Length: 4638
    Wed Oct 12 15:09:01 2005 Date: Wed, 12 Oct 2005 07:01:37 GMT
    Wed Oct 12 15:09:01 2005 Content-Type: text/html; charset=gb2312
    Wed Oct 12 15:09:01 2005 Server: achttp/2.0 (cached)
    Wed Oct 12 15:09:01 2005 Last-Modified: Wed, 12 Oct 2005 04:11:35 GMT
    Wed Oct 12 15:09:01 2005 ETag: “4aa7e0-121e-434c8cf7”
    Wed Oct 12 15:09:01 2005 Accept-Ranges: bytes

  • Anonymous says:

    但是恨奇怪,当且这页的http信息头却是UTF-8,感觉不是一个web server.

    Wed Oct 12 15:17:18 2005 GET /?p=119 HTTP/1.1
    Wed Oct 12 15:17:18 2005 Host: http://www.kdolphin.org
    Wed Oct 12 15:17:18 2005 Accept: */*
    Wed Oct 12 15:17:18 2005 Referer: http://www.kdolphin.org
    Wed Oct 12 15:17:18 2005 User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)
    Wed Oct 12 15:17:18 2005 Pragma: no-cache
    Wed Oct 12 15:17:18 2005 Cache-Control: no-cache
    Wed Oct 12 15:17:18 2005 Connection: close
    Wed Oct 12 15:17:19 2005 HTTP/1.1 200 OK
    Wed Oct 12 15:17:19 2005 Connection: close
    Wed Oct 12 15:17:19 2005 Date: Wed, 12 Oct 2005 07:17:14 GMT
    Wed Oct 12 15:17:19 2005 Content-Type: text/html; charset=UTF-8
    Wed Oct 12 15:17:19 2005 Server: Apache/1.3.33 (Unix) PHP/4.3.11
    Wed Oct 12 15:17:19 2005 X-Powered-By: PHP/4.3.11
    Wed Oct 12 15:17:19 2005 X-Pingback: http://www.kdolphin.org/xmlrpc.php

  • kDolphin says:

    我知道是服务器的设定造成gb2312的,wp1.2以前也是不能自动识别,但是从wp1.5以后就很正常了。他们确实在同一个服务器。

  • Anonymous says:

    它的可以而你的静态html不可以,我猜测原因是它的cgi文件开始有类似

    的设定(如果是PHP的话),而你的是静态的html,不能修改header.

  • Anonymous says:

    字符编码的问题太讨厌了,我非常希望UTF-8一统天下。

  • Anonymous says:

    上面那个被过滤了
    < ?php
    header(“Content-Type: text/vnd.wap.wml;charset=GB2312”);

  • kDolphin says:

    恩,我也是这么想的,wp是php的,应该是强行定义了。

  • 桑葚 says:

    如果有.htaccess 支持,可以加上一句
    AddDefaultCharset UTF-8

    如果用php文件就没问题的话,你可以把Blogger发布的文件设成.php。
    把blog filename设成index.php,archive filename设成archive.php

  • windix says:

    文件扩展名改为.php
    最开头加上
    header(“Content-Type: text/html; charset=UTF-8”);

    可以写成一个单独的.php文件,统一include一下

  • kDolphin says:

    谢谢各位,最后还是使用.php作为后缀,模版开头使用[php header (‘Content-Type: text/html; charset=utf-8’);]来定义utf-8,archive的文件名也使用了.php。
    关闭了blogger.com的本身留言系统,这样才能避免每篇帖子使用独立文件,因为独立文件不受控制还是会使用html。留言和trackback系统用了第三方的haloscan。

  • 韬略 says:

    1. html中指定了charset=gb2312, 那么文件格式必须是gb2312(即default)
    2. html中指定了charset=utf-8, 那么文件格式必须是utf8格式.
    Notepad, UE, Editplus等编辑器都支持这种转换. 其实对于纯英文的文件, 这种转换是没有意义的, 只针对文件中有汉字的情况.
    我建议都用utf-8格式, 火星人都可以看.

  • lemonhall says:

    恩,最后的解决方案是对的。。。PHP强制改HEADER。。
    以前遇到过这样的服务器。

Leave a Reply

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).