Characters like à not displaying correctly from MySQL

后端 未结 3 1381
长发绾君心
长发绾君心 2020-12-07 04:35

I have a problem when displaying results from a database in an HTML file in two computers.

So, in one computer it shows a name like this:

SAUL FRANCI         


        
相关标签:
3条回答
  • 2020-12-07 04:49

    Editing php.ini won’t help you much in a case like this.

    What is the data collation of the database giving you an issue? By default, most MySQL installs set latin1_swedish_ci instead of utf8_general_ci for newly created databases.

    Change the collation of the database & try again.

    ALTER DATABASE [name of your database] CHARACTER SET utf8;
    

    If this is a specific table, the collation can be changed as so:

    ALTER TABLE [name of your table] CONVERT TO CHARACTER SET utf8;
    

    And if it is a specific column in a table:

    ALTER TABLE [name of your table] MODIFY [name of your column] [other settings] CHARACTER SET utf8 COLLATE utf8_general_ci;
    

    Or perhaps you could export the current database, create a new database with this command & reimport the data:

    CREATE DATABASE [name of your database] CHARACTER SET utf8 COLLATE utf8_general_ci;
    

    And if you want to make a permanent change to the MySQL install on the machine giving you an issue, go and edit my.cnf. The following would set the whole chain to UTF-8:

    [client]
    default-character-set=utf8
    
    [mysql]
    default-character-set=utf8
    
    [mysqld]
    collation-server = utf8_unicode_ci
    init-connect='SET NAMES utf8'
    character-set-server = utf8
    
    0 讨论(0)
  • 2020-12-07 04:57

    add <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> to the head of your html

    0 讨论(0)
  • 2020-12-07 05:01

    You could set PHP to output the content as UTF-8:

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

    In your HTML document you can specify to the browsers that the content it is UTF-8, by putting this in the HEAD of your pages:

    <meta charset="UTF-8">

    0 讨论(0)
提交回复
热议问题