相关疑难解决方法(0)

如何在PHP中打开名称中包含unicode字符的文件?

例如,我有一个这样的文件名 - проба.xml,我无法从PHP脚本打开它.

如果我将php脚本设置为utf-8,那么脚本中的所有文本都是utf-8,因此当我将其传递给file_get_contents时:

$fname = "?????.xml";
file_get_contents($fname);
Run Code Online (Sandbox Code Playgroud)

我得到文件不存在的错误.原因是在Windows(XP)中,所有带有非拉丁字符的文件名都是unicode(UTF-16).好的,所以我试过这个:

$fname = "?????.xml";
$res = mb_convert_encoding($fname,'UTF-8','UTF-16');
file_get_contents($res);
Run Code Online (Sandbox Code Playgroud)

但是错误仍然存​​在,因为file_get_contents无法接受unicode字符串...

有什么建议?

php string unicode

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

php ×1

string ×1

unicode ×1