views:

144

answers:

1

Hello,

The database has a ton of entries that were not escaped because they were inputted manually when they were inserted so they look like: Don't inside of the entry, but when I try to display them they have a weird characters when I output in PHP. Before I would put anything into the database I would usually use mysqli_real_escape_string and then do the same when I go to retrieve the data, but since the data is already stored without using real_escape how do I display it properly?

The character being displayed instead of the single quotes looks like this: �

If it helps the data is stored as 'text'.

Thanks!


For future users of the same problem here's the steps:

  • Check your website headers to see what the encoding is
  • Check your mysql table columns and make sure they match.
  • If they don't change them to match. utf8_general in mysql and utf8 in my HTML worked for me
  • You will have to go back through the old mysql tables and update them so the new encoding is set properly.
  • New entries should work fine
  • When you output your results in PHP (or I guess whatever language you use), depending on if you are using any validation, you may have to use mysqli_real_escape_string or a similar function, such as stripslashes()
+3  A: 

You'll need to read up on text encoding.

The usual solution is to make sure everything (the content-type encoding on your pages, and your mysql) are set to UTF-8

Chances are your data is Latin1 and you're displaying UTF-8 or vise versa

JasonWoof
+1 Exactly and here's a nice introduction to encoding issues: http://www.joelonsoftware.com/articles/Unicode.html
Andomar
thanks for the input guys... My encoding on the site is utf-8, and I changed the database column to be utf8-general-ci, but it's still having the same problem... anything else i should switch?
krio
Seems to me you've gotta figure out what that data in your database is. You might have to convert the existing data too. First I'd test that when you put new data in, and then display it, it comes out right. Then figure out how to upgrade/convert the existing data in your database
JasonWoof
AWESOME! thanks for your help. new info is working. I just have to go through and edit some of the old. thanks
krio