Best practices in PHP and MySQL with international strings

前端 未结 5 859
一个人的身影
一个人的身影 2020-12-08 03:22

It often happens that characters such as é gets transformed to é, even though the collation for the MySQL DB, table and field is set to utf8_general_ci. T

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 04:16

    Things you should do:

    • Make sure Apache puts out UTF-8 content. Do this in your httpd.conf, or use PHP's header()-function to do it manually.
    • Make sure your database connection is UTF8. SET NAMES utf8 does the trick.
    • Make sure all your tables are set to UTF8.
    • Make sure all your PHP and template files are encoded as UTF8 if you store international characters in them.

    You usually don't have to do to much using the mb_string or utf8_encode/decode-functions when you do this.

提交回复
热议问题