2

I need to learn all these encoding stuffs well. Because this is the third time I'm wasting my time with silly wrong encoding problems. Here is the problem:
I have a simple php file.

  • File is in the format of UTF-8
  • If I run my local server, it makes ı => ı and ö => Ü
  • If I rename extension as HTML it works perfectly, so the problem is local server, definetely.

To correct this issue, I have done the following

  1. I've read this, this and this
  2. Double checked the file encoding, it's UTF-8
  3. Added the meta tag <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  4. Added the header inside php tag: header("Content-type:text/html; charset: UTF-8");
  5. Added the internal encoding inside php tag mb_internal_encoding('UTF-8');
  6. Corrected the line in php.ini file default_charset = UTF-8
  7. Added the following in httpd.conf file: AddDefaultCharset utf-8
  8. Everything is hard-coded, so I don't use database, it's not related to mysql encoding

I'm using WAMP, and machine is Windows 7 English. I'm completely exhausted, therefore, I really need help.
Thanks.

Community
  • 1
  • 1
Cihad Turhan
  • 2,749
  • 6
  • 28
  • 45
  • What is your browser telling you about the received HTTP headers? It is useless to try to set them correctly without verifying this effort really changed something. – Sven Mar 11 '13 at 21:00
  • Wow, I found something here. It says `Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3` in **Request Headers** and `Content-Type:text/html; charset: UTF-8;charset=iso-8859-9` in **Response Headers**. How can I correct this and where is the problem? – Cihad Turhan Mar 11 '13 at 21:07
  • The request header does not really matter. The response header definitely is wrong. If you correct it, things might work better. – Sven Mar 11 '13 at 21:11

2 Answers2

0

Checks whether the document encoding is UTF-8 without BOM

and if does not work try utf8_encode() and utf8_decode()

EDIT

$text = "A strange string to pass, maybe with some ø, æ, å characters."; 

foreach(mb_list_encodings() as $chr){ 
        echo mb_convert_encoding($text, 'UTF-8', $chr)." : ".$chr."<br>";    
 } 
  • As far as I know, `utf8_encode() and utf8_decode()` is for strings to convert. But this is the whole document not a couple of strings. And yes it's without BOM. – Cihad Turhan Mar 11 '13 at 21:10
  • Netbeans and Notepad++, but it's because of Response Header as Sven said in the comment above. I'm searching for the problem. – Cihad Turhan Mar 11 '13 at 21:19
  • I think your problem is not wrong chars, it's more a wrong encoding http://php.net/manual/es/function.mb-convert-encoding.php – Sander Saar Mar 11 '13 at 21:23
0

In the end I found problem. I wrote

header("Content-type:text/html; charset: UTF-8"); 

After Content-Type, we need to have put : but after Charset we need to put equal sign = which was very frustrating for me. So,

header('Content-Type: text/html; charset=utf-8');

solves the problem.

Cihad Turhan
  • 2,749
  • 6
  • 28
  • 45