我在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在第30行:b“”a;b;c;d;e;f\r\n 1;2;3;4;5;6\r\n
文件中没有b“.我试图用记事本++和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/