Problem: Accented characters displaying as question marks

Had this problem a while ago on a web site (Linux, Apache, MySQL, PHP).  It was difficult to track down and fix, so I thought I would post the solution here.  Accented characters (like é) coming from text stored in the database were displaying as question marks.  (Note — the character set in the database is ISO-8859-1  aka Latin-1.)

To track down the problem, I changed the character encoding manually using the browser to the aforementioned ISO-8859-1 (known in IE as Western European (ISO)).  The page looked fine.  So then the problem was getting the encoding to be that way by default.  Using Chris Pederick’s Web Developer Toolbar for Firefox (an utterly essential tool), Information > View Response Headers, I saw that Apache was sending an HTTP header saying Content-Type text/html; charset=utf-8.  Therefore, the browser was setting the encoding to Unicode.  To fix it, I added this line to the .htaccess file:

AddDefaultCharset On

This sets Apache’s default charset to ISO-8859-1.

My next challenge was updating the .htaccess file on the web site.  In the FTP program I normally use, WS_FTP, the .htaccess file was invisible (since the period at the beginning makes it a hidden file).  The program didn’t even prompt to OK overwriting it, even when I did overwrite it!  It was a lot easier to update it using FileZilla.

blog comments powered by Disqus