Issue with utf-8 encoding using PHP + MySQL

后端 未结 10 1541
谎友^
谎友^ 2020-12-16 12:41

I moved data from MySQL 4 (they were originally set to latin2 encoding) to MySQL 5 and set encoding to utf-8. It

10条回答
  •  臣服心动
    2020-12-16 13:17

    You don't have to set your PHP and HTML files to utf-8.

    You just have to set your output encoding to UTF-8 and the browser will display appropriately.

    In HTML:

    
    

    In PHP:

    header('Content-Type: text/html; charset=UTF-8');
    

    When you get a string that is UTF-8 from the MySQL table, it will be UTF-8 all the way to browser output unless you convert the encoding. It's the way that the browser inteprets it.

提交回复
热议问题