11 Vote

PHP: Strange rhombuses (�) instead of special characters in MySQL result despite using UTF-8 encoding

Question by Compi | 2012-08-25 at 16:37

On a website generated with PHP, I want to display the results of a MySQL query. The MySQL table is encoded with UTF-8 and also in my HTML page, I have specified an UTF-8 encoding in the head of the source code. Also in phpMyAdmin all special characters are displayed correctly.

Nevertheless, instead of the special characters, weird rhombuses and diamonds are outputted. For example on my homepage, the word "Müller" becomes "M�ller" with this rhombus with a question mark on it in the middle.

I already know, that similar problems can occur when codings do not match. However, this time it should work, because the codes should be correctly. Can someone help me?

ReplyPositiveNegative
1Best Answer1 Vote

Try to add the following line to your script immediately after connecting to the MySQL database:

mysql_query("set names 'utf8'");

If you have packed the connecting to the database in a separate file, that you are integrating with an include into your pages with MySQL, you can directly write down the line in this file.
2012-08-26 at 17:10

ReplyPositive Negative
Reply

Related Topics

PHP: Sending an E-Mail

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.