gpt4 book ai didi

php - 在 PHP 5.3 和 Windows Vista 中使用日文文件名?

转载 作者:可可西里 更新时间:2023-11-01 11:10:19 27 4
gpt4 key购买 nike

我目前正在尝试编写一个简单的脚本来查看文件夹,并返回 RSS 提要中所有文件名的列表。但是我遇到了一个大问题......每当我尝试读取其中包含日文字符的文件名时,它都会将它们显示为?。我已经尝试过这里提到的解决方案:php readdir problem with japanese language file name - 但是由于某些原因它们不工作,即使是:

header('Content-Type: text/html; charset=UTF-8');
setlocale(LC_ALL, 'en_US.UTF8');
mb_internal_encoding("UTF-8");

在顶部(导出为纯文本,直到我能解决这个问题)。

我能做什么?我需要这个来工作,但我没有太多时间。

最佳答案

function fx_dir_utf8 ($path)
{
// use this as failback on windows for usual dir listing
// give it a UTF-8 path and receive a UTF-8 listing
$path = iconv ('UTF-8', 'UTF-16LE', $path);
$cmd = 'cmd /U /C dir '. str_replace ('/', '\\', $path);
// windows command line returns CP850 or UTF-16LE
$dir_str = shell_exec ($cmd);
$dir_str = iconv ('UTF-16LE', 'UTF-8', $dir_str);
print_r ($dir_str);

// further parse $dir_str
return ($dir_str);
}

关于php - 在 PHP 5.3 和 Windows Vista 中使用日文文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2887909/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com