Character Encoding and Zend_Form

Here’s a poser for you. Open up a controller and its view and try this:

Controller:

$this->view->utf8 = 'Si Señor!';
 $this->view->html = 'Le Crépe';
$btn1 = new Zend_Form_Element_Button('btn1');
 $btn1->setLabel($this->view->utf8);
$btn2 = new Zend_Form_Element_Button('btn2');
 $btn2->setLabel($this->view->html);
$this->view->btn1 = $btn1;
 $this->view->btn2 = $btn2;

View:

<?php echo 'utf-8: '.$this->utf8.'<br />'
 'html: '.$this->html.'<br />'
 'btn1: '.$this->btn1.'<br />'
 'btn2: '.$this->btn2; ?>

Output:

utf8: Si Se�or!
html: Le Crépe
btn1: ()
btn2: (Le Cr&eacute;pe)

the (buttons) render, but:
the first one is blank (kind of expected as the utf8 variable doesn’t display either)
the 2nd one displays a label, and the html variable worked as we knew it would, however the &acute; entity is displaying in the label.

what does this mean?
does it mean that! the Zend_Form_Element_Button has doubly encoded it?
it must have sent Cr&amp;eacute;pe to the browser!

This is busting my chops! Send it unencoded and it fails to render the label, and send it encoded and it gets encoded twice 😐

Screen Shot 2013-02-06 at 22.02.22

UPDATE: You’ve checked character encoding in your code, mac textedit, the db, the templates, the form decorators,  the form filters, the forums, irc, but guess what? you forgot the IDE.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s