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

How to open file in PHP that has unicode characters in its name?(如何在 PHP 中打开名称中包含 unicode 字符的文件?)
本文介绍了如何在 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...

有什么建议吗?

推荐答案

这些是目前的结论:

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

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

Thus the conclusion this not doable in PHP 5.

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Why can#39;t I update data in an array with foreach loop?(为什么我不能用 foreach 循环更新数组中的数据?)
Foreach for arrays inside of an array(Foreach 用于数组内的数组)
PHP array get next key/value in foreach()(PHP 数组在 foreach() 中获取下一个键/值)
Using preg_match on a multidimensional array to return key values arrays(在多维数组上使用 preg_match 返回键值数组)
php foreach as key, every two number as a group(php foreach 为key,每两个数字为一组)
Treat a PHP class that implements Iterator as an array(将实现 Iterator 的 PHP 类视为数组)