I use the apache server hosted by my department in the university. Unfortunately, the apache server was set to use ascii as the default encoding. So even if you use charset in the meta tag, it is not gonna be respected by the browser.
But I have to use Chinese characters now and then. Previously, I translated Chinese characters to Unicode code and include it in the document using the &# hack. But it is only useful for page having a few characters.
There is a better way to do that: encode the charset information in the filename, and apache will output the proper encoding header based on that. This is possible thanks to the AddCharset lines in the conf file, such as the line below:
conf/httpd.conf:AddCharset UTF-8 .utf8
So if you have a file whose names ends in .html.utf8, apache will serve the page as if it is encoded in UTF-8 and will dump the proper character-encoding directive in the header accordingly.
I don’t know you or your blog, but this page saved me today. Thanks. Actually I’ve been thinking about starting a blog for the exact same reason…just document what I figure out just in case someone else is working on the same problem.
Thanks for the comments. I was about to close my blog. But your comment made me to keep blogging. Maybe let me know the link to your blog when you set up one, so that I can link to it on mine. Happy blogging.
Nice fix, but it only works for static pages, how do you do when you have to serve PHP pages and even as you saved them in UTF8 and set the charset meta, the server keeps displaying it in ISO-8859-1?
Anyway, it is a real cool solution already.
@Frederic: You could set the encoding using the php header() function:
header(‘Content-Type: text/html; charset=utf-8′);
or
header(‘Content-Type: text/html; charset=iso-8859-1′);
Cheers
Peter
@Peter
Thanks for the tip! I had a problem with the character encoding on an Apache server.
The header() function works great!
Cheers!
Julien
Hey, ty very much.. had exact same problem which mike has.
thanks a lot! also solved my problem