1

I'm attempting to get my web development environment running on my MacBook (OSX 10.10 with MAMP), but I'm stuck on an annoying character encoding issue. When originally developing my site in a Windows environment, I went with ISO-8859-1 encoding and never had any problems with character encoding.

Now, when I run my site locally on my MacBook, I get these � characters in text pulled from the database. I tried to solve the issue by changing the database from ISO-8859-1 to UTF-8 collation: I created a new database with UTF8_unicode_ci collation, imported the tables from the old database and changed collation for tables and fields to Unicode.

Seeing that this didn't help, I made an attempt by renaming a small table, and recreating it from scratch directly in UTF8 - but to no avail.

Don't know where else to search or what to do. Can someone please point me in the right direction ?

Are there maybe any settings in php or mysql which are relevant to this and would have default settings which are different on a Mac (I've never played around with this kind of parameters on either platform).

1

Unfortunately, getting character encodings right means checking multiple places. Data can be corrupted in half a dozen places. You need to go through and check each of them.

  1. How did you import the data from your Windows machine? Did you use mysqldump? Did you copy the database tables? If you used mysqldump you need to use the --default-character-set=ISO-8859-1 option. Similarly, when importing the db on the mac, you may need to specify the character set on the command line.
  2. When using PHP, you need to tell it what character set to use when connecting to the database..
  3. When outputting the webpage, you need to specify the character set in the content type.

If in all these places, you use ISO-8859-1, then you shouldn't get any more corrupted data.

The biggest problem with Latin 1 as your chosen character set is that it can't represent all languages. It can only deal with Western European languages such as English, Spanish, and German. You may wish to convert to UTF-8 at some point which is a much larger character set and can accomodate pretty much all the languages on earth. Converting is not as easy as specifying ISO-8859-1 everywhere though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.