PHP encoding issues with quotes (“„) and other special characters

Go To StackoverFlow.com

0

I've a problem with encoding on german website. I have a text:

„Eröffnungsfeier FIS Alpine Ski WM 2011“

When this text is saved into database I get ? instead of those quotes.

I've tried placing

header("Content-Type: text/html; charset=utf-8");
mb_internal_encoding("UTF-8");
setlocale(LC_ALL, 'de_DE.utf-8');

On the top of the file without success.

When I've used

mysql_set_charset('utf8', $connect);

But then, when inserting text above after reaching first character like ö the rest of the text is stripped.

The table charset and collation is UTF-8. Script file is saved as UTF-8 without BOM.

I lack of ideas where to look.

2012-04-05 18:08
by Sylwester Kardziejonek
Seems you did it well. Could you provide a link to the page? Did you set a http-equiv meta tag other than utf-8? I would check the page that inserts the text into the database - martinstoeckli 2012-04-05 19:05
Do you publish on a self-administered web server? Maybe you forgot to generate the locale in cause here (edit /etc/locales.gen, uncomment whatever you want, then locale-gen as root), it happened to me many times :- - Victor Nițu 2012-04-06 00:50


0

The things I did helped. Especially mysql_set_charset('utf8', $connect);. The problem was that there was some unwanted code left by another programmer (utf8_decode). Looks like he couldn't deal with utf-8 encoding other way.

I've also found out that mysql_set_charset('utf8', $connect); is not really needed if you're consistent with the encoding from the beginning.

2012-04-06 08:26
by Sylwester Kardziejonek


1

1) Check the schema of your database - are the text fields set up to store utf-8?

2) It sounds like the page posting to this script is not sending UTF-8. Does it have the correct Content-Type header? What does echo urlencode($var) show? (that's a neat hack to see the raw bytes you're getting)

2012-04-05 18:15
by Cal
The table charset is UTF8. Fileds have collation of utf8generalci - Sylwester Kardziejonek 2012-04-05 18:39
Updated answer with another possible solutio - Cal 2012-04-05 18:41
Ads