问题描述
例如,我有一个这样的文件名 - проба.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 字符的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)