2

I am trying to understand some problem at the UTF-8 encoding at the forum i am building, For start, I am using:

    <?xml version="1.0" encoding="utf-8"?>

and:

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

So the xml encoding is utf-8 and same is for the meta charset, also the files i am working with is UTF-8 and inside the Notepad++ it is UTF-8 without BOM, at the sql server the database and the tables are utf8_general_ci,

The problem is when i am inserting the data from the php code i see the data ok at the browser but weird at the sql server,

when i inserting the data from the sql server i see the data ok at the sql server but weird at the browser, If anyone know something please i will be very thankful.

3
  • 2
    Have you SET NAMES 'utf8' ? You can do this with mysql_set_charset("utf8") or $db->set_charset("utf8") before making any queries Commented Aug 5, 2012 at 12:18
  • use this in php header('Content-Type: text/html; charset=utf-8'); plus adding @Esailija query after connection directly, assuming you are using mysql Commented Aug 5, 2012 at 12:19
  • Thank you i shoulded set the charset at the connection same is here: stackoverflow.com/questions/4361459/php-pdo-charset-set-names Commented Aug 5, 2012 at 12:36

2 Answers 2

1

What kind of sql server do you use? I case of postgres or mysql, you should define the tables and or the fields as utf-8 aware.

Otherwise, when the db was filled via csv and the data inside are not utf-8 encoded, the result on your pages will be then also not utf-8 encoded.

In that case, you can transform the characterset manually.

Sign up to request clarification or add additional context in comments.

Comments

1

$db = mysql_connect(...);

/* change character set to utf8 */ mysql_query('SET NAMES utf8 ');

Simples!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.