Forum Moderators: open
I noticed some strange behavior with special characters and htmlentities($test, "UTF-8") and html_entity_decode($test, "UTF-8"). And this despite the fact that collation encoding for my database was UTF-8, HTML charset was also set to UTF-8.
After doing some searches, I found out that I should use the statement - mysql_query("SET NAMES 'utf8'");
And indeed, thanks to the is_utf8() function available at W3C, I noticed that results from my SQL queries were not in UTF-8 unless I use the SET query mentionned above.
I even now checked, using the same function, that passed variable (GET/POST) from forms are in utf-8 and deliver an error message if it fails.
And when inserting/updating data, I now always use the _utf8 statement, like this INSERT INTO $tcat (`id`, `title`) VALUES (NULL, _utf8'".$form_title."')"; for field that are text, longtext, blob, etc.
So after more intense reading, I made sure that I was in free-hassle UTF-8 environment (configuring default charset in ini, httpd.conf, apache, mysql, etc.). I was quite happy to see that everything worked as expected and released to know that everything was set-up for a multilingual website.
Nonetheless, when uploading the content on my host, I got error messages... Oups, they have an older version of MYSQL (4.0.24) that do not have the utf-8 unicode installed (only available in 4.1.x++).
Now I am really stuck! The best solution would be to move to a new host that has a newer version of MYSQL but it is kind of hard.
Am I the only one to use the MYSQL utf-8 functions cited above? Do you also have problems with utf-8 encoding? And any PHP functions that I can use to encode variable into utf-8?
Sorry for the long post and thanks for reading it... Just some food for though.
Tomda
I know that links are not allowed but this resource below is really great and give a very insteresting summary of what's going on with new MYSQL version and its character support.
[helpguide.inmotionhosting.com...]
The good news is that:
There are our two Unicode character sets. You can store texts in about 650 languages using these character sets.
w've been using Mysql 4.1 and php5 with utf-8 content for a couple of years now, so long as you configure everything to use utf-8 as a default charset, it should work like a charm.
One thing you haven't mentionned, if y're using web forms, then it could be usefull to add an attribute to the form tag like this <form accept-charset="utf-8"..... so that any content pasted into the form fields gets converted to utf-8 & not html entities if the document meta content type is not properly set