I have a database in .csv format that I have exported to my MySQL database and whose records I want to view on a website using PHP.
The problem is that some of the characters are encoded in the .csv file, for example \xe9
that it corresponds to the unicode character é.
The word Atlético
shows it to me asAtl\xe9tico
The field that stores the text in the database, I have declared it as VARCHAR with collation utf8_spanish_ci
How could I fix it?
Many things must be taken into account:
1) The first thing you should do is open the .csv file then click on file-> save as 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 "encoding" normally this by default in "ANSI" you must change it to "utf-8" then save it again with extension .csv
2) Check that in the section of your web forms there is the following meta tag :
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, place after selecting the database in mysql (mysql_select_db) :
To double guarantee that everything remains in utf-8 in the database
Observation: I have placed mysql as an instruction because I don't know if you have php7, if so you should change where it says mysql for mysqli because the mysql instructions are obsolete since PHP version 5.5.0 and removed since PHP 7.0.0. To see more of this click here
4) Also remember to save all the files of your .php project in utf-8 encoding since many of the text editors come by default in ANSI encoding (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 as the first line:
6) If none of the above has worked, it would only remain that after executing the query in mysql just before displaying the information (printing it with echo) place first:
where
$mostrar
is any field obtained from the table you did select to. I put it last because it has to be done every time you display 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 already have the problem solved. All the best!