Ask your Symfony questions! Pay money and get answers fast! (more info)

Why would I get garbage character if everything is encoded UTF8? Symfony


I have a German name with an umlaut.

The database is MySql. It has a UTF8 character collation.

If I look at the character in phpMyAdmin, it looks correct.

If I look at the character in the terminal, using the mysql command line client, the character looks correct.

When it shows up on my website, it is a garbage character.

The encoding of the page is UTF8.

Where might something go wrong that this character would mis-render?


I'm making this custom call in one of my peer classes:

class GermanPhotosPeer extends BaseGermanPhotosPeer
static function getActiveSlides()

$c = new Criteria();
$c->add(GermanPhotosPeer::ACTIVE, 'Y');
//$c->add(GermanPhotos::REFERENCE_DATE, date(),Criteria::LESS_EQUAL);
$rows = GermanPhotosPeer::doSelect( $c );


What config files govern this?

Answers (5)


Bill Hunt answers:

What version of symfony & doctrine are you running? In symfony < 1.3 / doctrine < 1.2, you needed to set the character encoding manually:

Versions after that you can set them in your databases.yml:

class: sfDoctrineDatabase
dsn: mysql://admin:[email protected]/foo
default_table_charset: utf8
default_table_collate: utf8_general_ci

Other things to check would include your mysql my.ini file to make sure that your database charset and default charset are set to utf8


Arturo Linares answers:

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

marshall comments:

We already have this on the web site:

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

Arturo Linares comments:

what happens if you htmlentities() the string? or utf8_encode/utf8_decode?


michalg answers:


1) Do you have UTF 8 as your client encoding in databases.yml?

2) Can you show any utf8 characters on your site? Make a test:
- add some variable in action with utf8 text
- echo it in view


Martin Palacio answers:

Are your php files saved with utf-8 encoding? How do the garbage characters look like? It's a question mark?

Option 2: Check the collation of:
* mysql default collation for client connections
* database default collation
* table default collation
* field collation


GlobalOrangeLab answers:

UTF-8 is the default encoding used by symfony, Even you can check with following setting.

charset: utf-8

2) Check Following
-> Mysql default collation
-> database, table and filed collation

Hope this helps!