求助:UTF-8

kDolphin @ 6:32 pm October 11th, 2005

  由于我的空间提供商的默认编码是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开始却正常了。

延伸阅读:

  1. 海豚的WordPress Theme教程 part3
  2. 在Putty中使用中文
  3. 為模版添加簡單的導航欄
  4. 海豚的WordPress Theme教程 part2
  5. 簡單的Menu制作

21 Responses to “求助:UTF-8”

  1. Hui
    October 11th, 2005 19:25 | |
    1

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

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

  2. kDolphin
    October 11th, 2005 19:35 | |
    2

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

  3. jtam
    October 12th, 2005 00:38 | |
    3

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

  4. hsuyo
    October 12th, 2005 00:53 | |
    4

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

  5. Platinum
    October 12th, 2005 02:21 | |
    5

    1. 一定要在 之前

    Title

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

  6. Platinum
    October 12th, 2005 02:23 | |
    6

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

    测试一下

  7. Platinum
    October 12th, 2005 02:24 | |
    7

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

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

  8. virushuo
    October 12th, 2005 03:02 | |
    8

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

  9. kDolphin
    October 12th, 2005 04:21 | |
    9

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

  10. Anonymous
    October 12th, 2005 07:16 | |
    10

    是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

  11. Anonymous
    October 12th, 2005 07:19 | |
    11

    但是恨奇怪,当且这页的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

  12. kDolphin
    October 12th, 2005 07:26 | |
    12

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

  13. Anonymous
    October 12th, 2005 07:47 | |
    13

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

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

  14. Anonymous
    October 12th, 2005 07:49 | |
    14

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

  15. Anonymous
    October 12th, 2005 07:50 | |
    15

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

  16. kDolphin
    October 12th, 2005 08:31 | |
    16

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

  17. 桑葚
    October 12th, 2005 14:27 | |
    17

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

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

  18. windix
    October 12th, 2005 15:11 | |
    18

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

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

  19. kDolphin
    October 13th, 2005 01:53 | |
    19

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

  20. 韬略
    October 14th, 2005 16:04 | |
    20

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

  21. lemonhall
    January 23rd, 2006 11:47 | |
    21

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

Leave a Reply