开发者

renaming my files from .htm to .php screws up the character encoding..?

I was given the job to work in the SEO of a website that is entirely html and javascript. First thing I see, they have hardcoded the headers and the footers(which I want to edit) on every page.

I decided that I want to change all the .htm files t开发者_运维知识库o .php in order to take advantage of the php include function and to include the header and the footer as a separate file into every page(yes I know that I could've modify the .htaccess file to treat .htm files as .php but there is a couple of more reasons I wanted .php).

After the change, the special characters on the website started showing as question marks on black background or simply as a normal question mark. When I open the .php files from the cPanel of my host, i see at the top of the editor that encoding is UTF-8 so I don't understand what the problem is. What I do to fix this problem is some kind of "magic" that I hate and it doesn't always work from the first time - copy the code in the whole file, change the encoding to us-ascii, save(at this point the file becomes empty o.O), CLOSE, open back up, paste the code back, tell the editor to open it as utf-8(it creates a new file...), paste the code back in. Then the special characters(like cyrilic, etc.) are displayed properly.

I don't want to do this for as many pages are on the website plus I want to understand the proper way to do it. Anyone can provide any help?


The files encoding must match the charset declared by the HTTP header and the meta tags of your HTML files.

Do you have something like this in your HTML:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

When you inspect the HTTP headers with Firebug (or anything else) do you see something like this (watch for "Content-Type"):

Response Headers
Date              Thu, 22 Sep 2011 14:53:26 GMT
Server            Apache mod_fcgid/2.3.6 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
Expires           Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control     private, max-age=10800, pre-check=10800
Content-Language  EN
Last-Modified     Fri, 22 Jul 2011 13:22:29 GMT
Content-Type      text/html; charset=UTF-8

When you open the file in your editor and you check it's charset, is it the same as above? Make sur that if you use UTF-8, no BOM are added to your files (at least for PHP files).

I guess your editor messed thing up... Can you provide the URL to an actual page? It could help us to tell what's is exactly going on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜