Monday, April 29, 2013

Why UTF-8 doesn’t work to display European characters in the Codeigniter or PHP

Writing an application is easy. Writing an application that supports all characters from multiple languages? Not so easy.

The main problem comes from way back, when the main language in computing was English. The ASCII characters were given numbers from 1 to 128 a-z, A-Z, 0-9 and punctuation. That is fine for the English language but pretty much every other language out there has characters that don't fit in there. To address this, we have UTF-8, which can store extra characters as multiple-bits and is backwards compatible with ASCII.

To make your CodeIgniter application play nicely with UTF-8 you have a few things to think about.

CodeIgniter by default is set to use UTF-8 for much of its internal functionality, so just make sure the charset is set to UTF-8 in your application/config/config.php file.

$config['charset'] = "UTF-8";

Setting UTF-8 as meta tag in the header is not sufficient, if you are working European characters. For example, to display Swedish characters å,ä,ö in the website. 

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

You will get following rendered text in your browser.
Hej! Det h�r meddelandet �r p� Svenska.(default)

You have to save file as UTF-8 as well. But using the correct doctype and encoding for the document helps crippled browsers.

If you are using coda as text editor, Check at Text/Encoding to know which encoding are you using while saving the file.

If you save the file with correct encoding i.e Unicode UTF-8 , then you will get the correct result:

Hej. Det här meddelandet är på Svenska.

Hope this will help who is having problem.

Ref: and

No comments:

Post a Comment