Java 用PHP解码unicode转义字符
我有多个文本文件将应用程序翻译成不同的语言。这些文本文件来自Java应用程序,如下所示:Java 用PHP解码unicode转义字符,java,php,unicode,encoding,decoding,Java,Php,Unicode,Encoding,Decoding,我有多个文本文件将应用程序翻译成不同的语言。这些文本文件来自Java应用程序,如下所示: weather_501=m\u00E4ßiger Regen weather_701=tr\u00FCb weather_731=Sand / Staubsturm weather_802=\u00FCberwiegend bew\u00F6lkt 我使用以下PHP函数加载此文件,$locale是输出的语言: function loadTranslation($locale) { $this-&g
weather_501=m\u00E4ßiger Regen
weather_701=tr\u00FCb
weather_731=Sand / Staubsturm
weather_802=\u00FCberwiegend bew\u00F6lkt
我使用以下PHP函数加载此文件,$locale
是输出的语言:
function loadTranslation($locale) {
$this->_data = array();
$localeFilePath = PATH_LANG . '/text/textTx_' . $locale . '/properties';
if (file_exists($localeFilePath)) {
$localeFileHandle = fopen($localeFilePath, "r");
while (($line = fgetcsv($localeFileHandle, 1000, "=")) !== FALSE) {
$this->_data[$line[0]] = $line[1];
print_r($line);
}
fclose($localeFileHandle);
}
else echo 'Error: localeFilePath does not exist: '.$localeFilePath.'<br/>';
return $this;
}
函数加载转换($locale){
$this->_data=array();
$localeFilePath=PATH_LANG.'/text/textTx_.'$locale.'/properties';
如果(文件_存在($localeFilePath)){
$localeFileHandle=fopen($localeFilePath,“r”);
而(($line=fgetcsv($localeFileHandle,1000,“=”)!==FALSE){
$this->_数据[$line[0]]=$line[1];
打印(行);
}
fclose($localeFileHandle);
}
else echo“错误:localeFilePath不存在:”。$localeFilePath。“
”;
退还$this;
}
现在的问题是UTF-8的unicode解码/编码。我试了好几次,但都没有成功。例如,它为德国Umlauts工作,但不为像“ß”这样的字符工作。产出“mä�伊格尔再生”。
此外,我没有让json\u encode
或json\u decode
函数工作
也许有人能帮我,告诉我我做错了什么
注意:PHP版本5.5问题在于文本文件编码错误,原因很简单 文件现在已正确编码,一切正常