0

I've been dealing with a bug where a user will copy and paste text from an email onto a form on our page, but the text is cut off at special characters such as u201D (”) when it's inserted into the database with mysql_query().

On my development machine (windows) I backed up the database, dropped it, recreated it with CHARACTER SET utf8 and loaded the backup. Now it works correctly on my dev machine.

I tried the same fix on the live server (linux) and while everything shows up as utf8, the text is still being cut off.

My dev machine is running:
MySQL version: 5.7.9
PHP version: 5.6.16

The server is running:
MySQL version: 5.5.35-1ubuntu1
PHP version: 5.4.30
(We are planning to update MySQL / PHP, but a lot of code will need to be fixed first).

Does anyone know what the problem could be? Thanks.

Qirel
  • 25,449
  • 7
  • 45
  • 62
ChelseaB
  • 13
  • 4
  • 1
    Is the form set to send UTF data? http://stackoverflow.com/questions/3624681/utf-8-not-working-in-html-forms – Ejaz Sep 15 '16 at 17:07
  • 1
    [read this topic](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Martin Sep 15 '16 at 17:11
  • I echoed the query just before running it and it isn't cut off, so the form isn't the issue. – ChelseaB Sep 15 '16 at 17:16
  • 2
    Just because it displayed and you saw it doesn't mean that it was valid UTF-8. [Also, stop using `mysql_*()` functions. They've been deprecated for *years* and removed in PHP7.](http://www.phptherightway.com/#mysql_extension) – Sammitch Sep 15 '16 at 17:36
  • Okay, how can I check if it's valid UTF-8? And I would LOVE to be using mysqli functions, but that would require updating thousands of lines of code (which I am slowly doing!). – ChelseaB Sep 15 '16 at 17:47
  • See Ejaz's and Martin's links. – Sammitch Sep 15 '16 at 18:20
  • Got it. Adding this line to the top of my pages fixed it! header("Content-Type: text/html;charset=UTF-8"); Thanks! – ChelseaB Sep 15 '16 at 18:22
  • Please provide `SHOW CREATE TABLE`; need to check the _column_. – Rick James Sep 16 '16 at 00:45
  • Can you get the hex (eg, via `bin2hex`) in PHP? I would hope to see `E2809D`. – Rick James Sep 16 '16 at 00:46

0 Answers0