PHP - FTP filename encoding issue(PHP - FTP文件名编码问题)
问题描述
我会很简短.我的 FTP 函数返回错误的文件名编码
I will be brief. My FTP function returns wrong encoding of filenames
$conn_id = ftp_connect("site.com");
ftp_login($conn_id, "login", "pass");
ftp_pasv($conn_id, true);
$buff = ftp_nlist($conn_id, "./");
print_r($buff);
-> // result
array() {
[0]=> "��.txt"
}
文件名采用 Windows-1251 编码.
The file name has Windows-1251 encoding.
我尝试通过 nodejs 连接到 FTP,但它也返回了一些令人毛骨悚然的东西——òð.txt.
I tried to connect to FTP via nodejs but it also returns something creepy — òð.txt.
我的桌面客户端 (WinSCP) 可以正常工作.
My desktop client (WinSCP) however works fine with this.
PS:我尝试使用 utf8_encode - 但这也不适合我.
PS: I tried to use utf8_encode - but that's also not working for me.
推荐答案
如果编码是你可以尝试使用 mb_convert_encoding.下面的代码应该输出正确的值.
If the encoding is of you could try to change it using mb_convert_encoding. The code below should output the correct value.
<?php
echo mb_convert_encoding($buff[0], "UTF-8");
//or
echo mb_convert_encoding($buff[0], "UTF-8", "windows-1251");
?>
如果它不起作用,您可以尝试使用类似的方法找到正确的编码
If it doesnt work, you can try to find the right encoding using something like
<?php
foreach(mb_list_encodings() as $chr){
echo mb_convert_encoding($buff[0], 'UTF-8', $chr)." : ".$chr."<br>";
}
?>
这篇关于PHP - FTP文件名编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP - FTP文件名编码问题
基础教程推荐
- 如何替换eregi() 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
