Possible encode problems UTF-8

The common problem with fresh projects in php is that, when developing with Windows you sometimes might start programming with notepad. Well the problem arises when saving your work, because the default notepad saves your work in ANSI format. Looking the work in browser you only see strange characters and äüõü will not be displayed. To solve the problem is to save it as UTF-8 and make sure it changes the encoding.

You might see strange characters also by fetching and displaying data from database. To avoid that set the database “DEFAULT CHARACTER SET utf8” or by setting the value individually for each table. Well I did this, but the problem remains. Also set the MySQLi’s extension charset $mysqli->set_charset(“utf8”).

How does the browser know which encoding to use ? Basically browser parses the DOM tree and looks for meta tag on top with the correct charset like this

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

One thought on “Possible encode problems UTF-8

  1. Instead of meta tag you can use “Content-Encoding” http header field like “Content-Type: text/html; charset=utf-8”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s