【问题标题】:Decode unicode escape characters with PHP使用 PHP 解码 unicode 转义字符
【发布时间】:2014-08-08 08:10:19
【问题描述】:

我有多个文本文件可以将应用程序翻译成不同的语言。这些文本文件来自 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->_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;
}

现在的问题是 UTF-8 的 unicode 解码/编码。我已经尝试了几次尝试,但没有任何效果。例如,Decode unicode escape characters 适用于德语变音符号,但不适用于像 'ß' 这样的字符。输出“mäiger Regen”。 此外,我没有让 json_encodejson_decode 函数工作......

也许有人可以在这里帮助我并告诉我我做错了什么。

注意:PHP 5.5 版

【问题讨论】:

    标签: java php unicode encoding decoding


    【解决方案1】:

    问题在于文本文件,原因很简单,它们编码错误。

    文件现在已正确编码,一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多