Display UTF-8 from database

Website URL

http://receptenvanons.42web.io/

Problem

In my database the names are stored correctly in UTF-8 encoding (specifically the column shown on the page has the utf8mb4_general_ci coalition in the database). However, when displaying them on the website special characters like ö are replaced by a question mark.

How can I fix this? The website already contains the tag.

The website already contains the meta utf-8 tag.

I did try to mention it above but while i copied the tag it was not displayed properly.

Hi and welcome to the forum

Your test document is written as ANSI

Screenshot 2024-04-24 073655

the document must be written as utf-8, it is not enough just to declare it.


This is how your document should be when it is utf-8 (converted)
test.htm (44.5 KB)

5 Likes

If the data is read from the database, please note that by default, database connections on our hosting do NOT use UTF-8 encoding, but latin1 instead. So if you enter special characters through phpMyAdmin (which does use UTF-8 connections) and then display it on your site, it will appear garbled. The same is true if you do the reverse (write from your site and display in phpMyAdmin).

The fix is simple: you need to specify the connection character encoding in your PHP code.

If you use MySQLi: PHP: mysqli::set_charset - Manual

If you use PDO: PHP: PDO_MYSQL DSN - Manual

7 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.