如何在PHP中打开名称为Unicode字符的文件? [英] How to open file in PHP that has unicode characters in its name?

查看:83
本文介绍了如何在PHP中打开名称为Unicode字符的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For example I have a filename like this - проба.xml and I am unable to open it from PHP script.

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

If I setup php script to be in utf-8 than all the text in script is utf-8 thus when I pass this to file_get_contents:

$fname = "проба.xml";
file_get_contents($fname);

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

I get error that file does not exist. The reason for this is that in Windows (XP) all file names with non-latin characters are unicode (UTF-16). OK so I tried this:

$fname = "проба.xml";
$res = mb_convert_encoding($fname,'UTF-8','UTF-16');
file_get_contents($res);

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

But the error persists since file_get_contents can not accept unicode strings...

有什么建议吗?

推荐答案

到目前为止,这些都是结论:

These are conclusions so far:

  1. 除非源文件名是unicode,否则PHP 5无法使用unicode字符打开文件名.
  2. PHP 5(至少在Windows XP上是)无法处理unicode中的PHP源代码.

因此得出的结论在PHP 5中不可行.

Thus the conclusion this not doable in PHP 5.

这篇关于如何在PHP中打开名称为Unicode字符的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆