【问题标题】:Encoding a PHP properties file in UTF-8以 UTF-8 编码 PHP 属性文件
【发布时间】:2014-09-11 07:00:08
【问题描述】:

我有一个用 PHP 读取的属性文件。该属性看起来像这样:

destination = "bibliothèque"

然后,我想将该属性读取为 UTF-8。

function utf8_trim($str) {
    return preg_replace("/^[\p{Z}\p{Cf}\x{200e}\x{200f}\s]*([\s\S]*?)[\p{Z}\p{Cf}\x{200e}\x{200f}\s]*$/u", "$1", $str);
}

mb_internal_encoding("UTF-8");
$places = parse_ini_file($filename);
$destination_untrimmed = $places['destination'];
$destination = utf8_trim($destination_untrimmed); //FAILS on this step due to invalid encoding

我使用的是 Eclipse 3.8.1。如何将我的字符串以 UTF-8 格式输入到常量文件中?

【问题讨论】:

    标签: php eclipse utf-8 preg-replace properties-file


    【解决方案1】:

    您的 ini 文件不是 utf-8 编码的。

    【讨论】:

    • Windows > Preferences > General > Content Types,将 UTF-8 设置为所有内容类型的默认编码。需要更多?
    • 它不适合我,它适合提问者:)
    • 我知道,但是谢谢 :-) 我应该写一个更好的答案 ;-)
    • @secretformula:感谢您要求详细说明,因为我确实需要它。 :)
    猜你喜欢
    • 1970-01-01
    • 2010-10-26
    • 2012-08-02
    • 1970-01-01
    • 1970-01-01
    • 2011-03-16
    • 1970-01-01
    相关资源
    最近更新 更多