UTF-8 problem when saving to mysql

前端 未结 5 1464
轮回少年
轮回少年 2020-12-12 02:36

My website is using charset iso 8859 1


when user post

5条回答
  •  庸人自扰
    2020-12-12 03:21

    If you are trying to go to UTF8 after you are already using another encoding, try these steps:

    1. Run ALTER TABLE tablename CONVERT TO CHARACTER SET UTF8 on your tables

    2. Configure MySQL to default to UTF8 or just run the SET NAMES UTF8 query once you establish a database connection. You only need to run it once per connection since it sets the connection to UTF8.

    3. Output a UTF8 header before delivering content to the browser. header('Content-Type: text/html; charset=utf-8');

    4. Include the UTF8 content-type meta tag on your page. meta http-equiv="Content-Type" content="text/html; charset=utf-8"

    If you do all those steps, everything should work fine.

提交回复
热议问题