gpt4 book ai didi

php - SFTP 上的文件在开头显示附加字符

转载 作者:搜寻专家 更新时间:2023-10-31 20:57:36 24 4
gpt4 key购买 nike

我在 symfony 3.4 中有一个函数,它抛出文件中不存在的字符:

use Exception;
use phpseclib\Net\SFTP;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\VarDumper\VarDumper;

public static function getInfoFile(string $fileName, ContainerInterface $container)
{
$host = $container->getParameter('host');
$sftp = new SFTP($host);
if (!$sftp->login($container->getParameter('user'), $container->getParameter('pass'))) {
throw new Exception('Cannot connect to ' . $host);
}
$file = $sftp->get("/info/$fileName");

vardumper::dump($file); // See Response below

$file = preg_split('/\R/', $file);
reset($file);

// vardumper::dump($file); // This would now return each array element prepended with b"""

return $file;
}

返回:

Service.php on line 30: b""" A;B;C;D;E;F\r\n 1;2;3;4;5;6\r\n

这个b"""在文件中不存在。我试过用Notepad++和Excel打开,但看不到。

当我尝试对它使用 substr 时,b"""会保留下来,实际文件会被剪切。

我做错了什么?我想将每一行的 csv 文件读取到一个数组中,而没有这些神秘的 b"""

最佳答案

我找到了解决方案....

$file = $sftp->get("/info/$fileName");
$file = mb_convert_encoding($file, "UTF-8", "ISO-8859-15" ); // Add this

问题是编码。

关于php - SFTP 上的文件在开头显示附加字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53958819/

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