How to open file in PHP that has unicode characters in its name?(如何在 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...
有什么建议吗?
推荐答案
这些是目前的结论:
- PHP 5 无法打开带有 unicode 字符的文件名,除非源文件名是 unicode.
- PHP 5(至少在 Windows XP 上)无法处理 unicode 中的 PHP 源代码.
因此得出的结论是这在 PHP 5 中是不可行的.
Thus the conclusion this not doable in PHP 5.
这篇关于如何在 PHP 中打开名称中包含 unicode 字符的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 PHP 中打开名称中包含 unicode 字符的文件?


基础教程推荐
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01