Correctly display characters encoded in style \ xe9 [duplicated]

2

I have a database in .csv format that I have exported to my MySQL database and whose records I want to visualize in a web using PHP.

The problem is that some of the characters are encoded in the .csv file, for example \xe9 that corresponds to the unicode character é.

The word Atlético shows it to me as Atl\xe9tico

The field that stores the text in the database, I have declared it as VARCHAR with collation utf8_spanish_ci

How could I solve it?

    
asked by Pedro 29.12.2017 в 01:31
source

1 answer

2

You have to take many things into account:

1) The first thing to do is open the file .csv then click on file- > save how and when you get the screen of the location where you will save the file at the bottom you will find a tab that says "coding" is usually by default in "ANSI" you must change it to "utf-8" then save it again with extension .csv

2) Check that the section of your web forms is the meta tag below:

 <head>
  <meta charset="UTF-8">
</head>

3) Because you have already checked the collation of your database it only remains that after the connection string that you have in your php files, you place after selecting the database in mysql (mysql_select_db) :

mysql_query("SET NAMES 'utf8'");

To have a double guarantee that everything remains in utf-8 in the database

Observation: I have placed mysql as an instruction because I do not know if you have php7 if so you must change where mysql says mysql because the mysql instructions are obsolete since the version of PHP 5.5. 0 and removed from the PHP 7.0.0 version. To see more of this click Here

4) Remember to also save utf-8 all the files of your project .php since many of the text editors come by default in coding > ANSI (like what I explained in step 1)

5) If you have a .htaccess file in the root folder of your project, open the file and place it as the first line:

AddDefaultCharset utf-8

6) If none of the above has worked it would only be that after executing the query in mysql just before displaying the information (print it with echo) put first:

$mostrar = utf8_decode($mostrar);

where $mostrar is any field obtained from the table you made select. I put it last because it must be done every time you show information to the user from the table that is giving you those characters \xe9 .

You can check the utf8_decode here .

This is all. You should have solved the problem. Greetings!

    
answered by 29.12.2017 / 02:19
source