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

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

  • SOLVED

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?

UPDATE:

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);
$c->addAscendingOrderByColumn(GermanPhotosPeer::SORT_NUMBER);
$rows = GermanPhotosPeer::doSelect( $c );

return($rows);
}
}


What config files govern this?

Answers (5)

2010-06-18

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:

http://blog.marcw.net/tips/utf-8-on-all-your-tables-with-doctrine-and-symfony-1-2/

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


all:
foo:
class: sfDoctrineDatabase
param:
dsn: mysql://admin:[email protected]/foo
attributes:
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

2010-06-18

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?

2010-06-18

michalg answers:

Hello,

1) Do you have UTF 8 as your client encoding in databases.yml?
http://www.symfony-project.org/reference/1_4/en/07-Databases#chapter_07_propel

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

2010-06-18

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

2010-06-18

GlobalOrangeLab answers:

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

apps/frontend/config/settings.yml
all:
.settings:
charset: utf-8


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

Hope this helps!