問題描述
例如,我有一個這樣的文件名 - проба.xml,但我無法從 PHP 腳本打開它.
For example I have a filename like this - проба.xml and I am unable to open it from PHP script.
如果我將 php 腳本設(shè)置為 utf-8,那么腳本中的所有文本都是 utf-8,因此當(dāng)我將其傳遞給 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...
有什么建議嗎?
推薦答案
這些是目前的結(jié)論:
- PHP 5 無法打開帶有 unicode 字符的文件名,除非源文件名是 unicode.
- PHP 5(至少在 Windows XP 上)無法處理 unicode 中的 PHP 源代碼.
因此得出的結(jié)論是這在 PHP 5 中是不可行的.
Thus the conclusion this not doable in PHP 5.
這篇關(guān)于如何在 PHP 中打開名稱中包含 unicode 字符的文件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!