Kirk
Kirk

Reputation: 638

Handling Charset (User input -> Php -> Mysql and back again)

Please go here to see my problem, its within the card on the left hand side of the page: http://gumonshoe.net/magic/card/?card=258

Apostrophes are getting converted to ascii it looks like from various foreign text formats. I've seen this, but since I'm using american english which is probably the basic defaults I can't reproduce the error to test it.

I figure there's got to be a correct way to be passing the characters around, I just don't know what it is.

The answer I'm looking for will tell me where in this chain things are getting messed up.

User Form on web page for input >>
javascript method >>
php >>
mysql

As far as I can tell this is happening in PHP. Its definitely wrong in the database by the time it gets there.

I'd be most happy with a solution that fixes everything from this point on, rather than a patch to fix what's in the db already as I can just find/replace those instances easily enough.

Thanks for all the help. Searching gave me mixed results, but I couldn't find anything that outright seemed identical to my problem and explained it from the basics up.

Again, thanks much!

Does it have anything to do with this:

mb_internal_encoding

Upvotes: 1

Views: 140

Answers (1)

Alfred Godoy
Alfred Godoy

Reputation: 1043

It does not happen in just one place, it always happens in the communication between two ends. That could be in the communication between browser<->php or php<->mysql

You should make sure to have a charset meta tag in your html header, something like:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

That way, your web browser knows what charset to use when posting data to your server (and what charset to use when rendering your page).

When connecting to mysql, you should make sure that your connection is speaking the same charset at both ends, and that should be the same charset as the web browser is using:

mysql_query('set names utf8');

Now, you should be fine.

Upvotes: 1

Related Questions