Flo
Flo

Reputation: 1445

€ char is shown as ? in UTF8 Output

I have reworked a website and now it is xhtml valid etc and using UTF8. Everything is fine, but if anywhere in the Database is a Euro-char it is just displayed as a questionmark.

What would be the right way to fix this? As output is done by Typo3 i cant change much about that.

Upvotes: 2

Views: 867

Answers (6)

Stefan Gehrig
Stefan Gehrig

Reputation: 83622

What charset (encoding, collation,...) are you using for the database column that contains the € sign?

The problem could be that your data stored in this column ist mixed up because the € sign is a somehow difficult beast when not using UTF-8 character encoding. The problem ist that the € sign is encoded as \xA4 when using ISO-8859-15 and as \x80 when using Windows-1252 (the common Western-European charset on Windows machines). If your data inside the column is not encoded correctly MySQL won't be able to transcode it into UTF-8 correctly - even if you use SET NAMES utf8.

Upvotes: 2

Max Kosyakov
Max Kosyakov

Reputation: 292

DON'T issue both statements!

Don't issue

SET NAMES utf8
SET CHARACTER SET utf8

one after another. It can cause trouble. I already had bad experience with SET CHARACTER SET utf8 right after SET NAMES utf8.

I recommend to issue only SET NAMES ...

MySQL docs has explanations why: http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html

In short: SET NAMES ... sets connection's charset to the same as client ans result charset. while SET CHARACTER NAME... sets different connection's charset and collation.

Please read the doc and decide whichever it better in your case. Or even better make a test.

Upvotes: 2

karim79
karim79

Reputation: 342635

Try executing these queries before the queries that fetch data:

SET NAMES utf8
SET CHARACTER SET utf8

Upvotes: 5

rwired
rwired

Reputation: 1133

You could try something like

$value = iconv('ISO-8859-1', 'UTF-8//TRANSLIT', $value);

The "ISO-8859-1" part may be different depending on your MySQL table character encoding.

Upvotes: 0

Thomi
Thomi

Reputation: 11808

If you're sure you have the right character data (0x20AC), it could also be the fonts ont he client-side. If the font you are using does not handle that particular character, you'll just see some default question mark.

However, why not use the escape code €, which gives you: €

Cheers,

Upvotes: 0

ymv
ymv

Reputation: 2173

This might be due to wrong database connection encoding

Lookup SET NAMES sql statement

    $db_link = mysql_connect($host,$user,$passwd);
    mysql_query("SET CHARACTER SET 'utf8';", $db_link);
    mysql_query("SET NAMES 'utf8';", $db_link);

Upvotes: 4

Related Questions