Saturday, February 28, 2009

Encoding - UTF8

How to make sure the whole site is in UTF-8.

Send the following header.

header('Content-Type: text/html; charset=utf-8');

Can be done with Zend Framework the following way in bootstrap:

$response = new Zend_Controller_Response_Http;
$response->setHeader('Content–Type', 'text/html; charset=UTF-8', true);
self::$frontController->setResponse($response);


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

Setting the option form option:

<form accept-charset="utf-8">


In Zend_Form:

$this->setAttrib('accept-charset', 'UTF-8');

Making sure the database is also using UTF-8.
When setting up use:

$db->query("SET NAMES 'utf8'");

Zend_View can also be set to use UTF-8:

$view = new Zend_View;
$view->setEncoding('UTF-8');

Reference: http://www.phpwact.org/php/i18n/charsets

No comments: