Accented characters in mySQL table

后端 未结 6 646
别跟我提以往
别跟我提以往 2020-12-02 23:53

I have some texts in French (containing accented characters such as \"é\"), stored in a MySQL table whose collation is utf8_unicode_ci (both the table and the columns), that

6条回答
  •  情深已故
    2020-12-03 00:32

    I experienced that same problem before, and what I did are the following

    1) Use notepad++(can almost adapt on any encoding) or eclipse and be sure in to save or open it in UTF-8 without BOM.

    2) set the encoding in PHP header, using header('Content-type: text/html; charset=UTF-8');

    3) remove any extra spaces on the start and end of my PHP files.

    4) set all my table and columns encoding to utf8mb4_general_ci or utf8mb4_unicode_ci via PhpMyAdmin or any mySQL client you have. A comparison of the two encodings are available here

    5) set mysql connection charset to UTF-8 (I use PDO for my database connection )

      PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
      PDO::MYSQL_ATTR_INIT_COMMAND => "SET CHARACTER SET utf8"
    

    or just execute the SQL queries before fetching any data

    6) use a meta tag

    7) use a certain language code for French

    8) change the html element lang attribute to the desired language

    
    

    and will be updating this more because I really had a hard time solving this problem before because I was dealing with Japanese characters in my past projects

    9) Some fonts are not available in the client PC, you need to use Google fonts to include it on your CSS

    10) Don't end your PHP source file with ?>

    NOTE:

    but if everything I said above doesn't work, try to adjust your encoding depending on the character-set you really want to display, for me I set everything to SHIFT-JIS to display all my japanese characters and it really works fine. But using UFT-8 must be your priority

提交回复
热议问题