【发布时间】:2011-06-08 08:31:28
【问题描述】:
我正在开发 Zend 应用程序。我数据库中的数据以“utf8_unicode_ci”编码。 我在 application.ini 中声明:
resources.view.encoding = "UTF-8"
但是每当我尝试检索包含特殊字符的字符串时,例如
{'é', 'à', 'è',...} 在数据库中,除非我使用该函数,否则字符串不会显示:utf8_decode()
所以我尝试将字符集设置为 UTF-8 :
引导:
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;
}
布局:
$this->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf8');
echo $this->headMeta();
应用程序.ini:
resources.view.encoding = "UTF-8"
resources.db.params.charset = "utf8"
编辑:现在我可以在页面中显示特殊字符,但是当我从数据库中检索元素时,不显示特殊字符。
- 转义字符串返回
null($this->escape($string)) -
echo $string用?替换特殊字符
所以我仍然必须使用utf8_decode() 来显示它们。有什么建议吗?
感谢您的帮助!!
【问题讨论】:
-
顺便说一下,我的源文件编码设置为utf-8
标签: database zend-framework utf-8 character-encoding