在Windows上列出包含Unicode字符的目录 [英] List directories containing Unicode characters on Windows

查看:133
本文介绍了在Windows上列出包含Unicode字符的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows 2003编写一些PHP代码。我使用XAMPP Portable(复制到D :)。问题:

I am using Windows 2003 to write some PHP code. I use XAMPP Portable (copy to D:). The problem:

$path = 'D:\ebooks';
$all_file = scandir($path);
foreach ($all_file as $file) {
  if (is_dir("$path/$file") && $file != '.' && $file != '..') {
    echo $file . "<br />\n";
  }
}

当我调用脚本(带浏览器)时,我没有看到包含Unicode字符的任何目录(在D:\ebooks中)(我用越南语,日语,中文,捷克语测试)。

When I call the script (with browser), I didn't see any directories (within D:\ebooks) containing a Unicode character (I tested with Vietnamese, Japanese, Chinese, Czech).

但是如果我删除 is_dir($ path / $ file) ,目录显示许多奇怪的字符,许多 / code> characters。

But if I remove is_dir("$path/$file"), the directories display with many strange characters and many ??? characters.

如何解决问题?

推荐答案

不幸的是,有很多与PHP访问Windows文件系统相关的错误。虽然Windows将文件名存储为UTF-16,但PHP的内部使用了更老的ANSI API。所以最好只能使用ascii范围内的文件名,或切换到其他操作系统。

Unfortunately, there are a lot of bugs related to PHP access to a windows filesystem. While Windows does store the filenames as UTF-16, PHP's internals use the much older ANSI api's. So it's best to only do stuff with filenames that are in the ascii range, or switch to a different operating system.

这篇关于在Windows上列出包含Unicode字符的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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