Strange characters appear on HTML page

These are called gremlins and they are usually caused because whichever program is putting the quotes in is using the actual pretty / curly / smart quotes instead of the proper HTML entities. The fonts don't display right or don't have those characters in them and instead produced the funny symbol.

This issue can usually be fixed by making sure you are using the proper UTF-8 throughout the entire page generation and serving to users.

For example, if your data is stored in a database, make sure all the text fields use UTF-8 encoding. You should also set the charset when connecting to the database (if using PDO in PHP) or run a query SET NAMES utf8 after connecting, before you start fetching data.

PHP handles UTF-8 fine if you are not modifying strings. If you are, you will need to look into using its multi-byte mb_* functions.

On the page itself, add the content type meta tag. It should go right after the

tag.

<meta charset=utf-8">

You could also set this as a HTTP header instead.

There is a good article about that at:
http://ccs.uottawa.ca/webmaster/templates/faq/weird-characters.html
and
http://webmasters.stackexchange.com/questions/15709/strange-characters-appearing-on-websites-ascii-unicode


Properties ID: 000415   Views: 4642   Updated: 9 years ago
Filed under: