Why Does a Diamond with a Questionmark in It Appear in My HTML

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

Diamond shaped question mark while viewing title in HTML

You need to escape typographic characters. Instead of apostrophe use this HTML entity . Others can be found here http://www.w3.org/wiki/Common_HTML_entities_used_for_typography.

UPDATE

For local files: save it with editor that supports UTF8 (with BOM preferably). Open it in Chrome and check tools-encoding menu. It tells you what actual encoding is browser using.

If you are using some kind of server. In Chrome press F12 for developer tools then go to network tab, reload page. On right side of the panel look for Response header Content-Type.

ÆØÅ shows as diamond question marks

Your document is in fact encoded in ISO-8859-1 or windows-1252 or something similar. Declaring UTF-8 will thus break all non-Ascii characters.

You should open the file in your authoring tool and save it as UTF-8 encoded. If this cannot be done, change the meta tag to declare windows-1252 instead of UTF-8.

I’m assuming that the server does not declare the encoding in HTTP headers. If it does, then you will need to make the actual encoding to match the header.

Diamonds with question marks

This is a problem with your character encoding scheme.

I would recommend reading this article, where (close to the bottom of it), he shows you why you get that little diamond with question marks.

The £ sign is shown as a diamond with a question mark in the middle

The particular problem can have at least the following one or more causes:

  1. The JSP file is not by the editor (Eclipse, Netbeans, Notepad, etc) been saved using UTF-8 encoding.

  2. The server didn't use UTF-8 to decode the characters produced by the JSP to a byte stream before sending it over network.

  3. The browser didn't use UTF-8 to encode the byte stream from the network to characters.

Those problems can be solved as follows:

  1. Configure the editor to save JSP files using UTF-8. I'm not familiar with STS, but I know that it is Eclipse based, so it'll probably be the same as in standard Eclipse. Go to Window > Preferences > General > Workspace > Text File Encoding and then pick the right encoding in the dropdown.

    Sample Image

    An alternative is to use the HTML entity £ (as suggested by the other answerer), this way it's not relevant anymore in which encoding the JSP file is saved. All characters involved in the string £ are supported by the basic ASCII encoding already (every decent character encoding used in the world basically "extends" ASCII, so it'll always work) and the HTML interpreter (the webbrower) will translate the HTML entity into the right character.

  2. The server has to be instructed to use UTF-8 to decode the JSP output. This can on a per-JSP basis be done by

    <%@page pageEncoding="UTF-8" %>

    or on an application-wide basis by

    <jsp-config>
    <jsp-property-group>
    <url-pattern>*.jsp</url-pattern>
    <page-encoding>UTF-8</page-encoding>
    </jsp-property-group>
    </jsp-config>
  3. The browser has to be instructed to use UTF-8 to encode the HTTP response. This is to be solved by setting the charset attribute of the HTTP response Content-Type header to UTF-8, which is already implicitly done by the solution to cause #2.

See also:

  • Unicode - How to get the characters right?

How to prevent showing the diamond question mark symbol, even using mb_substr and utf-8

This is the answer

mb_substr($entry->description, 0, 490, "UTF-8");

Why are my special characters ' ' being replaced with diamonds with question marks?

The problem was I needed to change the encoding of my file. In PHPStorm, go to 'File' then 'File Encoding'. For me, I needed to choose 'UTF-8' encoding. I converted the code and now the ">>" characters show up fine in the website!



Related Topics



Leave a reply



Submit