Utf-8 Encoded HTML Pages Show Questions Marks Instead of Characters

UTF-8 encoded html pages show � (questions marks) instead of characters

When [dropping] the encoding settings
mentioned above all characters
[are rendered] correctly but
the encoding that is detected shows
either windows-1252 or ISO-8859-1
depending on the browser.

Then that's what you're really sending. None of the encoding settings in your bullet list will actually modify your output in any way; all they do is tell the browser what encoding to assume when interpreting what you send. That's why you're getting those �s - you're telling the browser that what you're sending is UTF-8, but it's really ISO-8859-1.

special characters turned into question mark after duplication of the same page

Its important to know if the characters are really converted to ?? even inside the HTML files, or just when you browse them by a browser.

If inside the html page characters are saved correctly and you see them as question mark in browser In most cases by adding
<meta charset="utf-8">
(best in <head> element) to the page will fix the issue.

But in other hand sometimes when you copy and paste , or duplicate an HTML to another HTML file, due your environment situation, the encode of the new HTML file might not be Unicode or UTF-8 therefore it internally convert all special characters to question marks. Ofc when you browse this new HTML page you will see the question marks because they are actually converted to question marks at the time of file creation ( or save ).
change encoding the HTML file

In this case its better to first change the file encoding and then paste the content again and save it.
Hope it helps

Characters on page coming out as question marks, despite charset= utf-8

You could try

<meta charset="ISO-8859-1" />

Question mark characters on HTML if I use UTF-8 and weird characters on SQL data if I use ISO-8859-1

When you see question marks, your document has not been stored in the correct encoding (should be UTF-8 in your case) or it isn't being served with the correct headers and/or meta tags.

If you want to work with special characters like è, your html document should be saved as UTF-8 and served as UTF-8:

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

Additionally, you have to use UTF-8 for your database connections:

…("SET NAMES utf8");

…("SET CHARACTER SET utf8");

And last but not least, you have to use UTF-8 for the database itself.

As you'll notice, you're already on the correct path… you just have to "use it all" (as I described above) instead of trying one thing at a time and ignoring the rest. It's the combination that makes it work. Simpler said: if you go "UTF-8", you will have to think "UTF-8" everywhere and stick to it in your html files, your headers, your meta tags, your database connections, and the database(s). Use the same encoding everywhere and stick to it, instead of using "a bit UTF-8 here and a bit ISO-whatever there".

Question mark characters display within text. Why is this?

The following articles will be useful:

10.3 Specifying Character Sets and Collations

10.4 Connection Character Sets and Collations

After you connect to the database, issue the following command:

SET NAMES 'utf8';

Ensure that your web page also uses the UTF-8 encoding:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

PHP also offers several functions that will be useful for conversions:

  • iconv
  • mb_convert_encoding

Why does a diamond with a questionmark in it � appear in my HTML?

This specific character � is usually the sign of an invalid (non-UTF-8) character showing up in an output (like a page) that has been declared to be UTF-8. It happens often when

  • a database connection is not UTF-8 encoded (even if the tables are)

  • a HTML or script source file is stored in the wrong encoding (e.g. Windows-1252 instead of UTF-8) - make sure it's saved as a UTF-8 file. The setting is often in the "Save as..." dialog.

  • an online source (like a widget or a RSS feed) is fetched that isn't serving UTF-8



Related Topics



Leave a reply



Submit