I am developping a Zend application. The data in my database is encoded in “utf8_unicode_ci”.
I declared in my application.ini :
resources.view.encoding = "UTF-8"
but whenever I try to retrieve a String containing special characters like
{‘é’, ‘à’, ‘è’,…} in the db, the string doesn’t display unless I use the function : utf8_decode()
So I tried to set the charset to UTF-8 in :
Bootstrap :
protected function _initDoctype() {
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype('XHTML_STRICT');
$view->setEncoding('UTF-8');
}
protected function _initFrontControllerOutput() {
$this->bootstrap('FrontController');
$frontController = $this->getResource('FrontController');
$response = new Zend_Controller_Response_Http;
$response->setHeader('Content-Type', 'text/html; charset=UTF-8', true);
$frontController->setResponse($response);
$frontController->setParam('useDefaultControllerAlways', false);
return $frontController;
}
Layout :
$this->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf8');
echo $this->headMeta();
application.ini :
resources.view.encoding = "UTF-8"
resources.db.params.charset = "utf8"
EDIT : Now I can display special chars in a page, but when I retrieve elements from the database, special chars are not displayed.
- an escaped string returns
null($this->escape($string)) echo $stringsubstitutes special chars with?
so I still have to use utf8_decode() to display them. Any suggestion ?
thanks for your help !!
Maybe you should try to edit your source files keeping UTF-8 as your editor’s encoding. Sometimes even if you use UTF-8 in your HTML headers, database encoding, etc, if your source files are in a different encoding, this could lead to that kind of errors.