Zend_View and UTF-8
On one of my projects, we read in an RSS feed from Wordpress, using Zend_Feed:
$feed = Zend_Feed::import('http://dormae-online.com/blog/?feed=rss2'); foreach($feed as $entry) { echo '<h2>' . $entry->title . '</h2>'; echo '<div>' . $entry->author . '</h2>'; echo '<div>' . $entry->pubDate . '</div>'; echo '<div>' . $entry->{'content:encoded'} . '</div>'; }
This is a wonderful system that allows us to take advantage of the content management features that Wordpress offers, while still presenting a consistent and simple interface for the visitor. There’s just one minor problem: Wordpress uses UTF-8 encoding, while Zend Framework defaults to Latin-1, causing some minor character flaws when presented things like ü or ä. To solve this, we tell Zend_View (and the browser) exactly which character coding to expect:
$body = new Zend_View(); $body->setEncoding('UTF-8'); $body->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8');
Does anyone know how to tell Zend to use UTF-8 by default?