我和你几乎一样的状态,
开发机器是windows + php 5.3
开发机器是Linux + php 5.2.14
ZF版本是1.10
我唯一的区别是:我曾经mb_internal_encoding("UTF-8");
在引导类中添加
仅供参考,当我打开文件时,我曾经从数据库中缓存所有编码为 UTF8 的文本(阿拉伯语),我按预期看到了阿拉伯语文本。
更新 :1-这是我完整的 initCache 函数,只是为了清楚起见
public function _initCache() {
mb_internal_encoding("UTF-8");
$frontendOptions = array(
'automatic_serialization' => TRUE,
'lifetime' => 86400
);
$backendOptions = array(
'cache_dir' => APPLICATION_PATH . "/configs/cache/",
///'cache_dir' => sys_get_temp_dir(),
);
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
Zend_Registry::set("cache", $cache);
}
说明:
1-任何早于 PHP 6 的 php 版本都没有对 UTF-8 的原生支持,
https://stackoverflow.com/questions/716703/what-is-coming-in-php-6
2-使php 5.3或5.2使用ICONV或MB_STRING处理UTF8
只需使用 var_dump(mb_internal_encoding());
你可以告诉 php 在内部使用ISO-8859-1,
你可以覆盖它var_dump(mb_internal_encoding("UTF-8"));
它会输出真(覆盖内部编码成功)
老实说,我不知道是否有更好的解决方案或者它有多糟糕?,
如果你有更好的我会很乐意采用它:)
更新 2
如果您不想使用该功能,请打开此文件"Zend/Cache/Backend/File.php"
并转到第 976 行更改:
protected function _filePutContents($file, $string)
{
$result = false;
$f = @fopen($file, 'ab+');
if ($f) {
if ($this->_options['file_locking']) @flock($f, LOCK_EX);
fseek($f, 0);
ftruncate($f, 0);
$tmp = @fwrite($f, $string);
if (!($tmp === FALSE)) {
$result = true;
}
@fclose($f);
}
@chmod($file, $this->_options['cache_file_umask']);
return $result;
}
成为这样:
protected function _filePutContents($file, $string)
{
$string = mb_convert_encoding($string , "UTF-8" , "ISO-8859-1"); // i didn't test it , use it at your own risk and i'd rather stick with the first solution
$result = false;
$f = @fopen($file, 'ab+');
if ($f) {
if ($this->_options['file_locking']) @flock($f, LOCK_EX);
fseek($f, 0);
ftruncate($f, 0);
$tmp = @fwrite($f, $string);
if (!($tmp === FALSE)) {
$result = true;
}
@fclose($f);
}
@chmod($file, $this->_options['cache_file_umask']);
return $result;
}
我没有手动测试,但它应该可以按预期工作
很高兴它有帮助!