我正在开发一个 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;
}
Layout :
$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()
显示它们。有什么建议吗?
感谢您的帮助 !!