Randall Jamison
Randall Jamison

Reputation: 329

Character Encoding Issues -- Text File to Database

I have a bunch of text files that were written to a Linux server, that I need to pull into the database. I'm using file_get_contents() to grab the contents of the files. The text files have a lot of special characters in them (things like this:àáâãäåæçèéêëìíîïòóôõöøùúûü) , and they just aren't going into the database correctly (this is specifically going into a Wordpress site).

Things I've checked or tried:

Depending on what I try, I get either the A with the little squiggly over it, or more commonly, a rectangle with what looks like the numbers 00 86 in it.

I'm stumped -- if anyone has any other suggestions, I'm all ears!

Upvotes: 1

Views: 367

Answers (2)

fred2
fred2

Reputation: 1110

Try mysql_set_encoding('utf-8'); For all database connections.

Upvotes: 0

s_p
s_p

Reputation: 4693

Make sure (in order of importance):

  1. Your data is UTF-8 encoded (this includes your database, if applicable).
  2. Your server is sending utf-8 headers.
  3. Your HTML has utf-8 meta tags.

numbers 1 and 2 are the most common problems. (Number 2 especially - if your server sends headers specifying a different encoding, the browser will try to use that encoding, even if the meta tag says "utf-8".)

Upvotes: 1

Related Questions