How to Get Rid of “White Question Mark in Black Diamonds” Display Error

In this post, we will talk about the "white question mark in black diamonds" issue and how to solve it.

If you've ever worked with databases for storing the content of your websites, and if you used different character encoding options, it is highly possible that you've come across this display issue before. What I am talking about is the white question mark in black diamond display error.

Before talking about what causes it and how to get rid of it, let me show you an example of how it looks:

How to Get Rid of 'White Question Mark in Black Diamonds' Display Error

As you can see from the above image, some of the characters within the context of the web page are not displayed as they should. Two characters that are not rendered correctly in this example are the single quote (') and the double quote (").

Single quotes and double quotes are heavily used in the coding of a web page such as in HTML, PHP and MySQL and therefore if you don't set them properly, the browser will get confused and will not display them correctly. At the time of writing this post, I checked it with four major browsers and while Chrome, Firefox and Safari displayed question mark in diamonds, Internet Explorer displayed a small rectangle.

What Causes "Question Marks in Diamonds" Display Error?

In this specific example, it was the type of character encoding of the database that caused this error. Although I created the tables of the database in UTF-8 character encoding format, the quotes did not display correctly. The problem was that, when I established a database connection to fetch the posts, I didn't specify the encoding format where I should.

How to Solve "Question Marks in Diamonds" Display Error?

To solve this small but annoying issue, you need to specify the character encoding in your database connection file using the set_charset function as demonstrated below via a simple database connection class:

class DB {
public static $db;
DB::$db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

Once you specify the character encoding and refresh your page, you will see that the question marks in diamonds will have gone. I am not sure if the database encoding is the only reason for this display error but it is the only cause that I know of so far.

f t g+ in