Which charset, DTD & encoding to use?

westmatrix posted 9 years ago in General
I use this below, but get funny chars like this; Feb
ansgar posted 9 years ago
How was this file created? It's obviously not HeidiSQL, as we don't export a meta-charset (yet... would be a good idea though)
kalvaro posted 9 years ago
My guess is that you are developing a web site with a MySQL backend, possibly written in PHP.

The web server must tell the browser what charset the document uses via a "Content-Type" HTTP header. You have many options to do so. I've you're actually using PHP, you can generate the header yourself:

<?php header('Content-Type: text/html; charset=utf8'); ?>

If you are using Apache, you can do it in an .htaccess file:

AddDefaultCharset utf-8
rosenfield posted 9 years ago
Putting the character set in a meta header inside the file is actually NOT a good idea.

This is because the character set must match the actual format the file is written in. You would need to manually keep them in sync.

If you're editing a file, use an editor capable of writing UTF-8 files. A file written in utf8 format will contain a three-byte header which the editor will automatically maintain without you having to do anything.

If you're serving files with a web server, the scripting engine (PHP, for example) should have an option where you can set which character set you want to serve to clients, usually latin1, utf8 or cp1252. The scripting engine will then set the correct Content-Type header to include the character set, and send it out in the HTTP header to match the HTTP contents it generates.

Also, talking about a combination of the above. If you use a text editor that puts the correct utf8 header in files you edit, and if those files are PHP files, then the PHP engine should recognize that the file it is compiling is in utf8, and translate text inside on-the-fly to whatever format you told PHP you'd like to serve to clients.

Hope it makes sense.
westmatrix posted 9 years ago

Please login to leave a reply, or register at first.