4

I have a really simple form that takes a textarea and places the contents inside a MySQL database and then a website displays that information. Up until now everything has worked fine including special characters like apostrophes and bullets, however, all of a sudden now apostrophes cause the form to error out and bullets show up as this: •

All the pages are meta encoded as UTF-8, the database collation is UTF-8 and the text area string is being processed by the utf8_encode command.

What could cause this to suddenly happen?

I've been searching around on here for an answer and I can only find situations where people are missing UTF-8 on the database or on the web pages/forms. My only assumption is a PHP version update by the host, however, I cannot confirm that as they use a proprietary system that doesn't let me see the current running version number and I don't know if it would be affected in this way.

If it matters, the textareas are always wrapped in HTML pre tags for formatting.

CdnXxRRODxX
  • 341
  • 5
  • 14

3 Answers3

2

I'm obviously a little behind when it comes to char encodings - make sure you're correctly declaring the charset.

https://www.w3.org/International/questions/qa-html-encoding-declarations

html5 only requires <meta charset="utf-8">. If you're using this, make sure you also use <!DOCTYPE html> at the top of your html, otherwise you may run into HTML4 issues where <meta charset="utf-8"> won't work.

Noah Kiss
  • 63
  • 4
1

• is the Mojibake for a Bullet. Use this for finding out what you did wrong.

Community
  • 1
  • 1
Rick James
  • 135,179
  • 13
  • 127
  • 222
  • I went through the guide to ensure I wasn't missing anything, however, my mobijake issue still persisted. I will, however, be using your linked post for future reference as there's some great info in there. – CdnXxRRODxX Apr 03 '17 at 21:38
  • It took me years to gather and simplify that link to that point. I would be interested to hear what the ultimate cause was; maybe I have something wrong in my link. – Rick James Apr 03 '17 at 22:05
  • I just posted my answer to this thread. To be blatantly honest, I'm thinking something happened on the host's end and I'm compensating for something they changed as there was some downtime around the time this issue arose. I'm not very well versed in anything but the basics of encoding so I could be wrong. – CdnXxRRODxX Apr 03 '17 at 23:14
  • `SELECT HEX(col) ...` to see if the data was _stored_ correctly. – Rick James Apr 03 '17 at 23:58
  • I did do that and all the data was intact, however, the bullets were showing as their mobijake equivalent. After running my answer the mobijakes were just bullet characters. – CdnXxRRODxX Apr 06 '17 at 20:22
  • Let's see the hex. – Rick James Apr 06 '17 at 21:40
1

After checking a few times that everything was encoded properly I ended up trying the following solution:

Before passing the data within my textarea to the MYSQL DB I ran this:

mb_convert_encoding(textareacontents, "HTML-ENTITIES", "UTF-8")

After I ran that line everything started working. I'm not entirely sure why this mobijake issue started happening at random, especially with all the proper charsets in place, however, this seemed to help. Hopefully this helps someone in a jam.

CdnXxRRODxX
  • 341
  • 5
  • 14