Character encoding


#1

I’m having some troubles with character encoding of files. When I upload a file that contains special characters such as á,é,í,ó,ñ the file ends un unreadable when later i try to download again to my system.

Which character encoding should I use?


#2

Usually, the best solution is to use UTF-8. If you are writing PHP files, put this at the top of your code:<?php header("Content-Type: text/html;charset=UTF-8"); ?>You may also want to back it up with a META element in the HEAD of your document, to act as a fallback for older browsers:<meta http-equiv="content-type" content="text/html;charset=utf-8" />Make sure you SAVE your file as UTF-8 or Unicode before you upload it.


Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


#3

Rather than using “META” hacks, you should get the server to actually serve the pages with the correct HTTP headers by using a .htaccess file with a line like:

AddDefaultCharset UTF-8

And make sure your page actually is encoded this way; if your editing program actually saves it as something else such as ISO-8859-1, use that in your headers instead.

– Dan


#4

That would be fine unless you had documents with differing character sets (for foreign languages, etc.). That’s why I suggested using PHP headers.


Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]