I have a problem with this web application and I am hitting a dead end. This site is on a LAMP setup. It doesn't seem to want to accept utf-8 characters but I have set the encoding on the php pages like the headers <? header('Content-Type: text/html; charset=utf-8'); ?> form that submits data into the mysql database. accept-charset="utf-8". The database is set to accept utf-8 (i think). When I insert español it inserts espa&ntilde;ol. I have tried everything. Any ideas? In mysql I am looking at these variables but can't figure out if there's something wrong here. Any help would be greatly appreciated. Thanks!

Variable_name | Value |
+--------------------------+----------------------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql/share/mysql/charsets/ |
| collation_connection | latin1_swedish_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
| completion_type | 0 |
| concurrent_insert | 1 |
| connect_timeout | 5

    Character sets for client, connection and result means your database will convert data from latin1 to utf8 when receiving or sending data. Change the db config, or always "SET names utf8" after connecting to the db.
    SET names changes those three character sets. Also, when changing connection, collation_connection is also changed to default for the specified character set. utf8_general_ci in this case. If you want something else you have to specify that explicitly. Refer to the MySQL manual for details.

      johanafm;10935381 wrote:

      Character sets for client, connection and result means your database will convert data from latin1 to utf8 when receiving or sending data. Change the db config, or always "SET names utf8" after connecting to the db.
      SET names changes those three character sets. Also, when changing connection, collation_connection is also changed to default for the specified character set. utf8_general_ci in this case. If you want something else you have to specify that explicitly. Refer to the MySQL manual for details.

      Ok thanks. It seems to be submitting the html entities but if I insert words like español and können I can actually search for those words and they return those records. I guess I need to find out where its encoding.

        Sloppy reading on my part. I thought you had character translation problems, but html entities are due to something else. It seems you are doing two translations from characters to html entities.
        If you convert characters to html entities before inserting, and then do the same when searching, you would still get your matches. This, however, should display properly since the browser converts html entities back into characters. But if you also do this conversion once more, then all the & will be turned into &amp;
        So k&#246;nnen will first be turned into k&ouml;nnen, and then turned into k&amp;ouml;nnen, which the browser turns back into k&ouml;nnen.
        Search your php code for the htmlentities function.

          I think you are calling html_entities in your final display page. Due to your database data is fine and it is not html_entities -ed. But your final display page is set to be utf-8, so you shouldn't html_entities the value.

          Just remove html_entities from your display html page.

          You can also use http://php.net/manual/en/function.html-entity-decode.php html_entity_decode to decode it.

          But due to it is utf-8, you should use the html_entity_decode($string, ENT_COMPAT, 'utf-8') to decode it.

            Write a Reply...