UTF-8 issues with characters from a MySQL database (e.g. é as à ©)

I know that there are hundreds of questions about UTF-8 issues, but I tried all the approaches that I could find, none of them helped.

Facts: I am trying to read a line containing é from my MySQL database and display it on a PHP page. In fact, it displays as é (but the font does not recognize it as such and therefore uses a different default font). Problems arose when I wanted to convert this string to a file name using PHP functions to replace strings. PHP does not recognize this as an é character at all.

Here is a summary of what I'm doing:

1) The string is stored in the MySQL database. MySQL Server Settings: Mapping MySQL Connections utf8_unicode_ci
MySQL charset: UTF-8 Unicode (utf8)
The database itself is configured to sort utf8_unicode_ci (MyISAM storage engine, not changeable due to a shared server)
The actual table is set to collcation utf8_unicode_ci (InnoDB storage engine)

é displays correctly in phpMyAdmin. Data is inserted into the database through a Java program, but I also tried this with manually entered data (entered in phpMyAdmin).

2) PHP default_charset is not set (NO VALUE), I am on a shared server and put the manual override of php.ini, it does not seem to work. Using ini_set("default_charset", 'utf-8'); works, but does not affect the problem that I have.

3) Before running the actual select query, I will ask SET NAMES 'utf8' . The query itself does not matter, but for testing I chose a simple SELECT title FROM items WHERE item_id = 1

4) The PHP file itself is encoded by UTF-8. I set the correct encoding for html with <meta http-equiv="content-type" content="text/html; charset=utf-8" />

5) To check the problem, I used htmlentities for the returned string (Astérix), checking the source code, which it converted to Ast&Atilde;&copy;rix , which of course is incorrect. Accordingly, the string is displayed in Astérix in the browser.

What is the possible reason for this? It seems to me that I installed everything that can be installed in UTF-8.

+4
source share
1 answer

http://php.net/manual/en/ref.mbstring.php - look at multi-byte string functions.

+3
source

Source: https://habr.com/ru/post/1395261/


All Articles