3

I have some text stored in MySQL database like this "Tom gave Sarah £5 for her book". Up until last Monday this displayed on the site perfectly when pulled from the site, showing "Tom gave Sarah £5 for her book".

Now, even though I have not changed/installed/uninstalled/updated anything at all, it has stopped working.

The old values in the database are being displayed as "Tom gave Sarah £5 for her book". On the form that saves this text to database, where it used to save to database fine as "Tom gave Sarah £5 for her book", it is now saving as "Tom gave Sarah ?5 for her book", and displaying on the site as this as well ("Tom gave Sarah ?5 for her book").

What would cause this? I am pulling my hair out to try and sort this out. I have been playing with utf8_encode/utf8_decode and using ISO-8859-1 and UTF-8 character set for the pages and although each method produces different results (eg "?5" / "£5" / "£5" / "�5" / "☐5" ), none are right.

The problem can't be MySQL because I can see £ signs fine in phpMyAdmin and the £ signs work on a different web server.

Help!

Tim
  • 812
  • 2
  • 11
  • 22
  • One solution for the display problem would be to store the pound sign as HTML entity (`£`) in the database. – Felix Kling Jan 21 '10 at 17:06
  • What encoding does your field in the database use? And what encoding do you use in your output and how do you declare it? – Gumbo Jan 21 '10 at 17:07
  • The database is latin1_swedish_ci and the database works fine with a second web server and £ signs, so must be something with PHP or Apache – Tim Jan 21 '10 at 17:12
  • What is the encoding of your output page as specified in your browser's "page properties" / "page info" dialog? – Pekka Jan 21 '10 at 17:19
  • At the moment the browser encoding is ISO-8859-1, and I have tried setting this to UTF-8 but this still doesn't work. – Tim Jan 21 '10 at 17:22

2 Answers2

3

Instead of repeating this over and over again, I'm just gonna leave you with a link:

UTF-8 all the way through…


If you follow the steps mentioned in chazomaticus answer, your problems will be gone.

In your specific problem database / table / field encoding is probably the issue.

Community
  • 1
  • 1
Alix Axel
  • 151,645
  • 95
  • 393
  • 500
  • Unfortunately if I change database to UTF-8 it messes things up on the web server that currently works fine, so don't want to do this. – Tim Jan 21 '10 at 17:29
  • @Tim: Then HTML encode the stuff before saving to the database and decode it when fetching. That's the only advice I can give you. – Alix Axel Jan 21 '10 at 17:35
1

If your database is set to utf8 that might not be enough. Make sure the connection character set is set to UTF8. Perform this query: 'SET NAMES utf8;'

bobby
  • 11
  • 1