views:

22

answers:

3

Hey, I created a php website that would simply load the text from a mysql database, when I open it in a browser the Arabic text is presented in gibberish but then when I change the encoding of my browser to UTF-8 it's displayed properly, how can I force the encoding to be UTF-8 so users don't have to change it?

The menu part of the website which also loads the menu items from the same database (different table, they both have the same coalition "utf8_unicode_ci") but they are all displayed as question marks. How can I fix this?

You can check out the website on test.bdsfilmfest.com

Thank you in advance :)

A: 

Your web server probably sends a iso-8859-1 content-type header by default.

Either change the web server's behaviour - it should be possible to do a

 AddDefaultCharset utf-8

in a .htaccess file in the root directory of your web site.

or override the header from within PHP in each individual file:

header("Content-Type: text/html; charset=utf-8");
Pekka
It’s rather the client that falls back to ISO 8859-1 as there is no character encoding specified.
Gumbo
This fixed the text but the menu text is still being displayed as question marks :S Thank you very much though :)
yousefcisco
@yousef is the database connection you use also encoded in UTF-8? Try a `SET NAMES utf8;` before making any queries
Pekka
It worked! the connection was not UTF-8 encoded. This is great :)
yousefcisco
AddDefaultCharset is a bad idea. If the document has a meta element signaling it has another encoding, the meta element will be ignored. It also prevents the browser from content-sniffing the document.
Artefacto
A: 

The most easy way is to set the default_charset somewhere (possibly in apache vhost conf, in php.ini, or .htaccess file), so you won't have to repeat sending correct headers each & every script.

Wrikken
A: 

Uncomment this:

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