I'm having a membership site (PHP script) allowing members to have a conversation in the forms of send/receive forms. These messages are saved inside the database (Inbox)

When I translated the language files and ran the script, all the Arabic translated text showed questions marks. so I added AddDefaultCharset WINDOWS-1256 line inside the .htaccess file and everything worked fine. The character encoding in the browser is showing (Arabic Windows 1256)

Then when testing to send/receive messages between members, I got strange characters like this ظ…طظ…ط¯ طµظ„ط§ط ط§ظ„ط¯ظ?ظ† in both their mail boxes and also inside the database. But when I change the browser's character encoding to UNICODE (UTF-8), these messages appear right showing Arabic characters but the whole site's Arabic text shows question marks?

I think there's a conflict in the encoding for the site... Can anyone help?

    Make sure ALL the character encoding, including the page's character set in the <head> tag, is UTF-8. Having conflicting character sets/encoding will cause problems like what you're describing.

      Always specify the content-type header with the appropriate content type / subtype and character encoding.

      # plain text
      header('content-type: text/plain; charset=utf-8');
      # html
      header('content-type: text/html; charset=utf-8');
      

      IE was the only browser (until IE8 iirc) who did not respect http content-type header and instead gave precedence to the content type meta tag when it comes to character encoding.

      But IE8 (IE9 as well?) does not respect the type/subtype specification of content-type headers - for "security reasons" (it makes no sense). They do however, albeit this being done for "security reasons" also specify a proprietary header called x-content-type-options which, wtih a value of "no-sniff" makes IE8 stopp sniffing and instead respect the content-type header.

      header('x-content-type-options: no-sniff');
      

      All in all, if you target IE7-, you should use <meta http-equiv="content-type" value="text/html; charset=utf-8>. If you don't, you can skip this and stick with only the content-type header.

        Thank you.

        I managed to fix it the primitive way cause I couldn't trace where the error is?

        Backed up everything, installed a fresh clean script and update necessary file. It took me around 3 hours.

          Write a Reply...