Basically, I have a form that restaurant owners can fill out that (among other things) asks for the business name.
If something like "Foobar Café" is entered, it is stored in the MySQL database as "Foobar Café". Why is it doing that?
Bot开发者_如何学Ch the HTML page and database table are set to UTF-8 encoding (the "business_name" field has a collation of "utf8_unicode_ci
"). Shouldn't that take care of everything? What exactly could be causing the special character "é" (&etilde;)
to be stored in the database as "é"
? It makes no sense.
Your database connection is probably not set to UTF-8.
At the start of your connection, issue the following query:
SET NAMES 'utf8';
That will set the connection character set to utf8 which will match the encoding and collation of your tables, code and client page.
I'm guessing it is from the form not mysql since the email comes from there. Look into that. Maybe you have a ”pre processor” of some sort.
Just wondering, why do you store html chars when you will be displaying that info to users? That's a recipe for disaster. XSS.
A quick fix, try using htmlentites on the data with uft-8 turned on. Send the email as html and you should be fine.
However, try to find the cause of the issue.
Edit. echo htmlentities($str, ENT_QUOTES, "UTF-8");
That should solve your issue. Charset for utf 8 must be defined
Check the settings for the respective db table or db, set it to to utf-8
精彩评论